title: Django cannot connect to running postgres docker container
body: <p>I am surprised that I cannot get this to work, as I have run a django applications with a postgres DB in docker containers multiple times, however, this time on my Linux machine the django application cannot connect to the postgres docker container, whereas on my Mac the setup works without a problem.</p>
  <p>I am getting the standard error:</p>
  <blockquote>
  <p>django.db.utils.OperationalError: could not connect to server: Host is unreachable
  Is the server running on host &quot;postgresdb&quot; (172.27.0.2) and accepting
  TCP/IP connections on port 5432?</p>
  </blockquote>
  <p>The postgres container is running and should be reachable. I check the IP address of the docker container and it seems correct. My docker-compose file looks like this:</p>
  <pre class="lang-yaml prettyprint-override"><code>version: &quot;3.8&quot;
  services:
    app:
      container_name: data-management
      restart: always
      build: ./
      ports:
        - '3000:3000'
      links:
        - 'postgresdb'
      volumes:
        - ./:/usr/local/share/src/app
      env_file:
        - .dev.env
  
    postgresdb:
      container_name: be-postgres
      restart: always
      image: postgres:13.4-alpine
      ports:
        - '5432:5432'
      volumes:
        - postgres-db:/var/lib/postgresql/data
      env_file:
        - .dev.env
  
  volumes:
    postgres-db:
  </code></pre>
  <p>The configurations are stored in an environment file, which is used in both containers to avoid any mismatches.</p>
  <pre><code>POSTGRES_PASSWORD=devpassword123
  POSTGRES_USER=devuser
  POSTGRES_SERVICE=postgresdb
  POSTGRES_PORT=5432
  POSTGRES_DB=data_management
  </code></pre>
  <p>The django DB settings are as standard as they could be:</p>
  <pre class="lang-py prettyprint-override"><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.postgresql',
          'HOST': os.environ['POSTGRES_SERVICE'],
          'NAME': os.environ['POSTGRES_DB'],
          'PORT': os.environ['POSTGRES_PORT'],
          'USER': os.environ['POSTGRES_USER'],
          'PASSWORD': os.environ['POSTGRES_PASSWORD'],
      }
  }
  </code></pre>
  <p>I am out of ideas as what could be causing this as this happens only on my Fedora machine and there are no issues when running on my Mac. I have already had SELinux problems with some docker volumes in the past, however, after googling I could not find any suggestions that SELinux could be the culprit again.</p>