Docker-compose with django could not translate host name "db" to address: Name or service not known : <p>I have currently a system built with docker-compose, it creates a Django application.</p>

<p>Up until now I've used a database inside a container (postgresql) in my testing build. Now I've changed the database from this container to an RDS instance in AWS.</p>

<p>Using Pg_dump I have recreated the database inside RDS and changed the settings.py, everything was supposedly normal. I have accessed the data from the database inside my webapp without any problems. </p>

<p>Everything was ok until I had to make a migration. Without the database container the Django container gives me this message:</p>

<blockquote>
  <p>django.db.utils.OperationalError: could not translate host name "db"
  to address: Name or service not known</p>
</blockquote>

<p>My Docker-compose.yml file before the changes:</p>

<pre><code> version: '2'

    services:
      db:
        image: postgres:9.5
        restart: always
        environment:
          POSTGRES_USER: testing
          POSTGRES_PASSWORD: tests
          POSTGRES_DB: test
        volumes:
          - /dbdata:/var/lib/postgresql/data
      django:
        build: ./django
        command: gunicorn contactto.wsgi:application -b 0.0.0.0:8000
        restart: always
        volumes:
          - ./django:/usr/src/app
          - ./django/static:/usr/src/app/contactto/static
        ports:
          - "8000:8000"
        depends_on:
          - db
</code></pre>

<p>Now after the changes:</p>

<pre><code>    version: '2'

    services:
      django:
        build: ./django
        command: gunicorn contactto.wsgi:application -b 0.0.0.0:8000
        restart: always
        volumes:
          - ./django:/usr/src/app
          - ./django/static:/usr/src/app/contactto/static
        ports:
          - "8000:8000"
</code></pre>

<p>And the DATABASES from settings.py .
Before:</p>

<pre><code>DATABASES = {
        'default': {
            'ENGINE': 'tenant_schemas.postgresql_backend',
            'NAME': 'testing',
            'USER': 'test',
            'PASSWORD': 'test',
            'HOST': 'db',
            'PORT': '5432',
        }
    }
</code></pre>

<p>After:</p>

<pre><code>DATABASES = {
        'default': {
            'ENGINE': 'tenant_schemas.postgresql_backend',
            'NAME': 'testing',
            'USER': 'test',
            'PASSWORD': 'test',
            'HOST': 'xxx.rds.amazonaws.com',
            'PORT': '5432',
        }
    }
</code></pre>

<p>The weird thing is, I can use the aws database inside my app... I can create users and do things inside the database and the changes appear. Now in the CLI I can't even use manage.py shell without the message.</p>

<p>I am completely lost.</p>
