title: Docker django.db.utils.OperationalError: could not translate host name "db" to address: Temporary failure in name resolution
body: <p>Seems like a common error. I followed every possible suggestion on Stackoverflow(adding links, network etc), but it makes no difference in my case. I am running on Windows.</p>
  <p>My Dockerfile:</p>
  <pre><code>#Pull base image.
  FROM python:3.9.5-slim
  
  #Usefull to get logs
  ENV PYTHONUNBUFFERED 1
  
  #Make local dir
  RUN mkdir -p /app
  
  #set as the working directory
  WORKDIR /app
  
  #https://luis-sena.medium.com/creating-the-perfect-python-dockerfile-51bdec41f1c8
  COPY requirements.txt .
  
  #now copy all the files in this directory to \code
  ADD . .
  
  #https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/
  RUN apt-get update &amp;&amp; \
   apt-get install -y postgresql-server-dev-all gcc python3-dev musl-dev &amp;&amp; \
   pip install -r requirements.txt &amp;&amp; \
   adduser --disabled-password --no-create-home app
  
  USER app
  
  #CMD python manage.py runserver
  CMD gunicorn --bind 0.0.0.0:8000 app.wsgi:application -k eventlet
  </code></pre>
  <p>Next, my docker-compose.yml:</p>
  <pre><code>services:
    web:
      build: .
      ports:
        - &quot;8000:8000&quot;
      volumes:
        - .:/app
      links:
        - db:db
      container_name: heritageapi_web_1
      depends_on:
        - db
      networks:
        - heritage-network
  
    db:
      image: postgres:13.3
      container_name: db
      restart: always
      networks:
        - heritage-network
      environment:
        POSTGRES_DATABASE: admin
        POSTGRES_USER: root
        POSTGRES_PASSWORD: root
        POSTGRES_ROOT_PASSWORD: root
      volumes:
        - .dbdata:/var/lib/postgres
      ports:
        - &quot;32768:5432&quot;
  
  networks:
    heritage-network:
      driver: bridge
  </code></pre>
  <p>My .env: DB_NAME=admin DB_USER=root DB_PASSWORD=root DB_HOST=db DB_PORT=5432</p>
  <p>Finally my settings.py:</p>
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql',
          'NAME': os.getenv('DB_NAME'),
          'USER': os.getenv('DB_USER'),
          'PASSWORD': os.getenv('DB_PASSWORD'),
          'HOST': os.getenv('DB_HOST'),
          'PORT': os.getenv('DB_PORT'),
      }
  }
  </code></pre>