title: Connecting pgadmin to postgres in docker
body: <p>I have a <code>docker-compose</code> file with services for <code>python</code>, <code>nginx</code>, <code>postgres</code> and <code>pgadmin</code>:</p>
  
  <pre><code>services:
    postgres:
      image: postgres:9.6
      env_file: .env
      volumes:
        - postgres_data:/var/lib/postgresql/data
      ports:
        - "5431:5431"
  
    pgadmin:
      image: dpage/pgadmin4
      links:
        - postgres
      depends_on:
        - postgres
      environment:
        PGADMIN_DEFAULT_EMAIL: admin@admin.com
        PGADMIN_DEFAULT_PASSWORD: pwdpwd
      volumes:
        - pgadmin:/root/.pgadmin
      ports:
        - "5050:80"
  
    backend:
      build:
        context: ./foobar  # This refs a Dockerfile with Python and Django requirements
      command: ["/wait-for-it.sh", "postgres:5431", "--", "/gunicorn.sh"]
      volumes:
        - staticfiles_root:/foobar/static
      depends_on:
        - postgres
  
    nginx:
      build:
        context: ./foobar/docker/nginx
      volumes:
        - staticfiles_root:/foobar/static
      depends_on:
        - backend
      ports:
        - "0.0.0.0:80:80"
  
  volumes:
    postgres_data:
    staticfiles_root:
    pgadmin:
  </code></pre>
  
  <p>When I run <code>docker-compose up</code> and visit <code>localhost:5050</code>, I see the <code>pgadmin</code> interface. When I try to create a new server there, with <code>localhost</code> or <code>0.0.0.0</code> as host name and <code>5431</code> as port, I get an error "Could not connect to server". If I remove these and instead enter <code>postgres</code> in the "Service" field, I get the error "definition of service "postgres" not found". How can I connect to the database with <code>pgadmin</code>?</p>