title: postgres container throws "forward host lookup failed: Unknown host"
body: <p>I'm working with docker image that uses Python3.6 as its base. All of the sudden it started crashing (exiting right after start up). So I bashed into the container and found out that
  it crashes because connection to containerized postgres database fails all of the sudden.
  The only error output I managed to get is <code>forward host lookup failed: Unknown host</code> which isn't telling me much.</p>
  
  <p>entrypoint.sh:</p>
  
  <pre><code>echo "Waiting for postgres..."
  
  while ! nc -z users-db 5432; do
    sleep 0.1
  done
  
  echo "PostgreSQL started"
  
  python manage.py run -h 0.0.0.0
  </code></pre>
  
  <p>error output:</p>
  
  <pre><code>Waiting for postgres...
  users-db: forward host lookup failed: Unknown host
  users-db: forward host lookup failed: Unknown host
  users-db: forward host lookup failed: Unknown host
  ...
  ...
  </code></pre>
  
  <p>Dockerfile:</p>
  
  <pre><code>FROM python:3.6.9-slim
  
  LABEL maintainer="abc"
  
  RUN apt-get update &amp;&amp; \
      apt-get install -y netcat &amp;&amp; \
      apt-get clean
  
  WORKDIR /usr/src/app
  
  COPY ./requirements.txt /usr/src/app/requirements.txt
  RUN pip install -r requirements.txt
  
  COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
  RUN chmod +x /usr/src/app/entrypoint.sh
  
  
  COPY . /usr/src/app
  
  CMD ["/usr/src/app/entrypoint.sh"]
  </code></pre>
  
  <p>What strikes me about this is that it worked wonderfully until now and without me making any changes to the database container the connection failed.</p>
  
  <p>What can I do to troubleshoot this ? If you need to review any files just ask and I'll share it here.</p>
  
  <p><code>docker ps</code>:</p>
  
  <pre><code>72d344cc61bf        tdd_nginx           "nginx -g 'daemon of…"   25 minutes ago      Restarting (1) 55 seconds ago                            tdd_nginx_1
  8ee2f8082e69        tdd_client          "npm start"              26 minutes ago      Up 25 minutes                   0.0.0.0:3007-&gt;3000/tcp   tdd_client_1
  1ccfc3ca5600        tdd_users-db        "docker-entrypoint.s…"   26 minutes ago      Up 26 minutes                   0.0.0.0:5435-&gt;5432/tcp   tdd_users-db_1
  --&gt;  62af29277b78        tdd_users           "/bin/bash -s"           22 minutes ago      Exited (130) 2 minutes ago   # &lt;-- keeps crashing
  </code></pre>
  
  <p>docker-compose file:</p>
  
  <pre><code>version: '3.7'
  
  services:
    users:
      build:
        context: ./services/users
        dockerfile: Dockerfile
      volumes:
        - './services/users:/usr/src/app'
      ports:
        - 5001:5000
      environment:
        - FLASK_ENV=development
        - APP_SETTINGS=project.config.DevelopmentConfig
        - DATABASE_URL=postgres://postgres:postgres@users-db:5432/users_dev
        - DATABASE_TEST_URL=postgres://postgres:postgres@users-db:5432/users_test
        - SECRET_KEY=bart_simpson
      depends_on:
        - users-db
  
    client:
      build:
        context: ./services/client
        dockerfile: Dockerfile
      volumes:
        - './services/client:/usr/src/app'
        - '/usr/src/app/node_modules'
      ports:
        - 3007:3000
      environment:
        - NODE_ENV=development
        - REACT_APP_USERS_SERVICE_URL=${REACT_APP_USERS_SERVICE_URL}
      depends_on:
        - users
  
    nginx:
      build:
        context: ./services/nginx
        dockerfile: Dockerfile
      restart: always
      ports:
        - 80:80
      depends_on:
        - users
        - client
  
    users-db:
      build:
        context: './services/users/project/db'
        dockerfile: Dockerfile
      ports:
        - 5435:5432
      environment:
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=postgres
  </code></pre>