title: Cannot connect to PostgreSQL in Docker through PHP
body: <p>I'm cant connect to PostgreSQL with php code. My Postgresql is docker container.
  I get an IP with:</p>
  
  <pre><code>docker inspect toshi_db_1
  </code></pre>
  
  <p>How I'm trying to connect: </p>
  
  <pre><code>$dbconn = pg_connect("host=172.17.0.2 port=5432 dbname=toshi_development")or die("Could not connect");
  </code></pre>
  
  <blockquote>
    <p><strong>Error</strong>: Warning: pg_connect(): Unable to connect to PostgreSQL server:
    could not connect to server: Connection timed out (0x0000274C/10060)
    Is the server running on host &quot;172.17.0.2&quot; and accepting
    TCP/IP connections on port 5432?</p>
  </blockquote>
  
  <p>I thought there could be problems in PostgreSQL.conf with listen_address configuration parameter, but it allows all connections, so I have no idea where the problem is.</p>
  
  <blockquote>
    <p><strong>UPDATE</strong>: I fixed it myself, just tried to expose wrong port in
    docker-compose file.</p>
  </blockquote>