3

I am using Pyscopg. DOCKER-COMPOSE:

 version: '3.7'

services:
  web:
    build: .
    command: python3 /code/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - 8000:8000
    depends_on:
      - db2
  db2:
    image: postgres:11

SETTINGS.PY:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': 'postgres',
        'HOST': 'db2',
        'PORT': 5432
    }
}

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

1 Answers1

2

It works, when you add

environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres

to docker-compose.yml file.

  • Searched for hours `POSTGRES_PASSWORD`...it was `POSTGRES_PASSOWRD` :-/ beware of typos! – swiss_knight Feb 02 '21 at 18:40
  • 2
    I got the same problem, please where and which position should add the above line of codes, I had tried many methods, but it just did not work for me. – Liang Wei Mar 25 '22 at 13:37