Yes you need to change host to db. You can also use environment variables in your setting like below.
DATABASES = {
"default": {
"ENGINE": os.environ.get("SQL_ENGINE"),
"NAME": os.environ.get("SQL_DATABASE"),
"USER": os.environ.get("SQL_USER"),
"PASSWORD": os.environ.get("SQL_PASSWORD"),
"HOST": os.environ.get("SQL_HOST"),
"PORT": os.environ.get("SQL_PORT"),
}
}
and add environment variables to docker-compose or add env_file. Below is docker-compose.
services:
web:
restart: always
build:
context: ./mmd_backend
dockerfile: Dockerfile.prod
command: gunicorn mmd_backend.wsgi:application --bind 0.0.0.0:8000
volumes:
- static_volume:/home/app/web/staticfiles
- media_volume:/home/app/web/mediafiles
expose:
- 8000
env_file:
- ./.env.prod
depends_on:
- db
db:
build: ./pg12-3.0
ports:
- 5436:5432
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.env.prod.db
nginx:
build: ./nginx
restart: always
volumes:
- static_volume:/home/app/web/staticfiles
- media_volume:/home/app/web/mediafiles
ports:
- 8000:8000
depends_on:
- web
volumes:
postgres_data:
static_volume:
media_volume:
and env file is as bellow
#.env
DEBUG=1
SECRET_KEY=7bhlblY8pY
SQL_ENGINE=django.contrib.gis.db.backends.postgis
SQL_DATABASE=db_name
SQL_USER=db_user
SQL_PASSWORD=db_password
SQL_HOST=db
SQL_PORT=5432