0

My django app is not dockerized, but I run postgres inside docker container using docker-compose.yml script. After docker-compose up I can connect to db with dbeaver, but not with django app. Every time I'm getting an error:

django.db.utils.OperationalError: could not translate host name "db" to address: 
Temporary failure in name resolution

File docker-compose.yml:

version: "3.9"
services:
  db:
    image: postgres:13
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    environment:
      - "POSTGRES_HOST_AUTH_METHOD=trust"
      - POSTGRES_USER="postgres"
      - POSTGRES_PASSWORD="postgres"
      - POSTGRES_DB="postgres"
    ports:
      - 5432:5432
volumes:
  postgres_data

Django project file config/settings.py:

...
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': env.str("DB_NAME"),
        'USER': env.str("DB_USER"),
        'PASSWORD': env.str("DB_PASS"),
        'HOST': env.str("DB_HOST"),
        'PORT': env.decimal("DB_PORT")
    }
}

1 Answer 1

1

It was some kind of pipenv error. When I restarted terminal and executed pipenv shell again and then python manage.py runserver everything worked just fine

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.