I have the django project which works with PostGresql db, both in docker containers.
It works Ok, but on highload sometimes gives the
django.db.utils.OperationalError: could not translate host name "db" to address: Temporary failure in name resolution
error.
Is there a way to tune the django db connector for more retries or more timeout to solve these case?
docker-compose.yml (with some changes) :
version: '3.5'
services:
django:
build:
context: ./django
dockerfile: Dockerfile
command:
python manage.py runserver 0.0.0.0:8000
volumes:
django_volume:/home/django/django/files/
ports:
8000:8000
env_file:
env.django
depends_on:
db
db:
build:
context: ./db
dockerfile: Dockerfile
volumes:
db_volume:/var/lib/postgresql/data/
env_file:
env.db
volumes:
django_volume:
db_volume:
django container's entrypoint.sh contains the cycle:
while ! nc -x $DB_HOST $DB_PORT ; do
sleep 0.1
done
exec "$@"
To be sure that db completely started before django start.