0

I want to deploy my django w postgres thanks to docker and I get an error like: django.db.utils.OperationalError: could not translate host name "db" to address: Name or service not known

This is my docker-compose :

version: '3'

services:
  db:
    image: postgres
    environment: 
        POSTGRES_USER: alban
        POSTGRES_PASSWORD: ***
        POSTGRES_DB:  plateforme
    restart: always
    ports: 
      - "5432:5432"

  web:
    build: ./plateforme_v2_1
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

This is my setting.py :

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

Does anyone here already get this problem ?

Thx

B. Go
  • 1,436
  • 4
  • 15
  • 22
ranisterio
  • 13
  • 3
  • Are you using docker or docker-compose to run it? – Sayse Dec 19 '19 at 17:49
  • @Sayse i'm using docker-compose – ranisterio Dec 19 '19 at 17:52
  • Does this answer your question? [Django docker - could not translate host name "db" to address: nodename nor servname provided, or not known](https://stackoverflow.com/questions/55081675/django-docker-could-not-translate-host-name-db-to-address-nodename-nor-serv) – richyen Dec 19 '19 at 18:35
  • Where specifically are you trying to connect to the database? (You can't from a `RUN` instruction in a Dockerfile, for example.) Can you show enough of your application code to demonstrate the problem? – David Maze Dec 20 '19 at 01:16
  • can u use this image: postgres:11 – khaled hadjali Jan 14 '20 at 08:52

1 Answers1

0

ur config should be like that ::

 DATABASES = {
        "default": {
            "ENGINE": "django.db.backends.postgresql_psycopg2
            "NAME": 'postgres',
            "USER": 'alban',
            "PASSWORD":'******',
            "HOST": 'db',
            "PORT": 5432,
        }
    }