https://github.com/shorotshishir/docker-django
https://github.com/shorotshishir/docker-django
django django-container docker docker-compose dockerfile linux python
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/shorotshishir/docker-django
- Owner: Shorotshishir
- Created: 2021-07-22T11:29:21.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-22T11:33:53.000Z (almost 5 years ago)
- Last Synced: 2026-03-11T12:16:44.782Z (3 months ago)
- Topics: django, django-container, docker, docker-compose, dockerfile, linux, python
- Language: Dockerfile
- Homepage:
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## django in docker
## creating a docker container for django development
this is how i create my django base template inside docker
## pre requisite
_Follow the official installation guide_
- docker-engine [link](https://docs.docker.com/engine/install/ubuntu/)
- docker-compose [link](https://docs.docker.com/compose/install/)
## Get Started
- pull this repo
- open directory in terminal
- type
```
docker-compose run web django-admin startproject .
```
- this will first run the service named `web` defines in the `services` in `docker-compose.yml`
- as it has dependency on db, db service will also start.
- if command executed successfully a django project will be created.
## Ownership of files
- in `linux` all files will be `root` owned, meaning cant modify without sudo command.
- type
```
sudo chown -R $USER:$USER .
```
- this will make all `existing` files owner to local user, i.e. modifiable without root
- Creating app using `python manage.py ` will make that `app owned by root`, thus run the above command again to get going.
## Database Configuration
- this repos uses postgres as the default `db`
- change the default database of django in `settings.py` to
```
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'pgdb',
'PORT': 5432,
}
}
```
- make sure the name, user and password of database matches with the data in `docker-compose.py`
## Django based commands
- to get access to the bash of docker type
```
docker exec -it bash
```
- run all django related command in this bash, e.g. `python manage.py makemigrations` or `python manage.py migrate` or `python manage.py createsuperuser`