title: How to connect from PgAdmin container to Postgres container
body: <p>I want to deploy 2 containers one for pgAdmin and one for Postgres with docker-compose. Containers are created correctly and I am able to login to pgAdin on my browser, but when I am trying to create a connection to Postgres, using localhost:15432 it does not work, but if I use 172.19.0.2:15432 it works. Is there a way to use the localhost for the connection or to assign a fixed port to my Postgres?</p>
  
  <pre><code>version: '3.5'
  
  services:
    postgres:
      container_name: rn_postgres
      image: postgres
      hostname: postgres
      ports:
        - "15432:5432"
      environment:
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: rn2020
        POSTGRES_DB: rnmonitor
      volumes:
        - postgres-data:/var/lib/postgresql/data
      restart: unless-stopped
    pgadmin:
      container_name: rn_pgadmin
      image: dpage/pgadmin4
      depends_on:
        - postgres
      ports:
        - "5555:80"
      volumes:
        - pgadmin:/root/.pgadmin
      environment:
        PGADMIN_DEFAULT_EMAIL: pgadmin4@pgadmin.org
        PGADMIN_DEFAULT_PASSWORD: admin
      restart: unless-stopped
  volumes:
    pgadmin:
    postgres-data:
  </code></pre>