title: How to connect to postgres created with docker-compose from outside host
body: <p>I think this problem should be very easy to solve, but I am pulling my hair out. I have the following docker-compose:</p>
  
  <pre><code>version: "3"
  services:
  
    pg-db:
      image: postgres:11
      environment:
        POSTGRES_PASSWORD: "postgres"
        POSTGRES_USER: "postgres"
        POSTGRES_DB: "postgres"
      ports:
        - 5432:5432
      #network_mode: host
  </code></pre>
  
  <p>Then I run <code>docker-compose up</code> and it starts the container</p>
  
  <pre><code>pg-db_1_78e7ec4a95e6 | 2020-02-21 13:53:53.928 UTC [1] LOG:  database system is ready to accept connections
  </code></pre>
  
  <p>I can connect to it with docker exec</p>
  
  <pre><code>docker exec -it docker_pg-db-compose_1_78e7ec4a95e6 psql -h pg-db -U postgres postgres
  </code></pre>
  
  <p>But I can't manage to connect to it by 'naked' psql:</p>
  
  <pre><code>psql postgresql://postgres:postgres@localhost:5432/postgres
  
  psql: could not connect to server: Connection refused
      Is the server running on host "localhost" (::1) and accepting
      TCP/IP connections on port 5432?
  
  psql postgresql://postgres:postgres@pg-dg:5432/postgres
  psql: could not translate host name "pg-db" to address: Name or service not known
  </code></pre>
  
  <p>I've tried with <code>network_mode</code> but it doesn't help.</p>