title: How to Connect to Docker Postgres Container from Host Machine
body: <p>I put together a Rails dev environment by following instructions from
  <a href="https://docs.docker.com/compose/rails/" rel="noreferrer">https://docs.docker.com/compose/rails/</a></p>
  
  <p>It works, but I am unable to connect to the Postgres server from the host machine. I am running macOS High Sierra. When I run <code>docker container ls</code> I see <code>5432/tcp</code> as the port for the Postgres container. Note that there's not IP listed in front of 5432. When I run <code>docker network inspect &lt;postgress_container_ID&gt;</code> I get 172.18.0.2 as the IP. </p>
  
  <p>But when I run <code>psql -h 172.18.0.2 -p 5432  -U postgres</code> I get </p>
  
  <pre><code>xpsql: could not connect to server: Operation timed out
    Is the server running on host "172.18.0.2" and accepting
    TCP/IP connections on port 5432?
  </code></pre>
  
  <p>What am I doing wrong?</p>