I am trying to dockarize my django app but I have a problem in configuring the database:
docker-compose.yaml:
services:
db:
image: postgres:13
container_name: db
# networks:
# - djangonetwork
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
# - POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_NAME=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
es:
image: elasticsearch:7.9.1
environment:
- xpack.security.enabled=false
- discovery.type=single-node
ports:
- "9200:9200"
- "9300:9300"
networks:
- elastic
volumes:
- ./data/elastic:/var/lib/elasticsearch/data
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
ports:
- "8000:8000"
environment:
- POSTGRES_NAME= postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
volumes:
- .:/app
# - /tmp/app/mysqld:/run/mysqld
depends_on:
- db
- es
networks:
- elastic
# - postdata
thesearchable:
build: ./thesearchable
ports:
- "3000:3000"
volumes:
- ./frontend:/frontend
volumes:
postgres_data:
networks:
elastic:
driver: bridge
in settings.py:
'default': {
"ENGINE": "django.db.backends.postgresql",
"NAME": "postgres",
"USER": "postgres",
"PASSWORD": "postgres",
"HOST": "db", # set in docker-compose.yml
"PORT": 5432, # default postgres port
}
I have found that many people faced this problem but none of the answers solved my problem and I always find this message
error django.db.utils.OperationalError: could not translate host name "db" to address: Temporary failure in name resolution
so how can I solve this?