this is how i create my django base template inside docker
Follow the official installation guide
- pull this repo
- open directory in terminal
- type
docker-compose run web django-admin startproject <name-of-your-project> .
- this will first run the service named
web
defines in theservices
indocker-compose.yml
- as it has dependency on db, db service will also start.
- if command executed successfully a django project will be created.
- in
linux
all files will beroot
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 <name-of-your-app>
will make thatapp owned by root
, thus run the above command again to get going.
- this repos uses postgres as the default
db
- change the default database of django in
settings.py
toDATABASES = { '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
- to get access to the bash of docker type
docker exec -it <container-id> bash
- run all django related command in this bash, e.g.
python manage.py makemigrations
orpython manage.py migrate
orpython manage.py createsuperuser