Docker Compose setup for Django/Postgres app. Based on the tutorial from the Docker documenation.
Docker and Docker Compose are required to be installed in your system.
Start your Django project with:
docker-compose run web django-admin startproject <your_project> .
Update DATABASES
contant in settings.py
module to point at the Postgres container:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'db',
'PORT': 5432,
}
}
Also update ALLOWED_HOSTS
contant in settings.py
module:
ALLOWED_HOSTS = ["*"]
Run the containers:
docker-compose up
Open your browser and navigate to http://0.0.0.0:8000
. If you see the congratulations page then you are all set.
If during the execution of the command docker-compose up
you see an error like this:
python: can't open file '/code/manage.py': [Errno 2] No such file or directory
Then you need to update the path to manage.py
module in docker-compose.yml
file:
command: python manage.py runserver 0.0.0.0:8000