title: Docker - Tomcat and PostgreSQL containers in same host - No Route to host
body: <p>I have containerized a web application running on Tomcat and started the container using the command,</p>
  
  <pre><code>docker run -d -p 8080:8080 tveuser/tve-repository:tve-services
  </code></pre>
  
  <p>I am also running a PostgreSQL container on the same host using the following command:</p>
  
  <pre><code>docker run -d  -p 80:80 -p  5432:5432 tveuser/tve-repository:tve-postgresql
  </code></pre>
  
  <p>i verified that the PostgreSQL is running by using phpPgAdmin but could not get tomcat to connect to it. 'docker ps' also tells me that both the containers are up and running.</p>
  
  <p>I connect the web application with the database through tomcat context.xml which has an entry like     </p>
  
  <pre><code>&lt;Parameter name="abc.connection.url" value="jdbc:postgresql://1.2.3.4:5432/dbname" /&gt;
  </code></pre>
  
  <p>where 1.2.3.4 is the docker host Ip in which the container is running.But i get the following error when i run the tomcat container:</p>
  
  <pre><code>org.postgresql.util.PSQLException: The connection attempt failed.
          at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:225)
          at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
          at org.postgresql.jdbc2.AbstractJdbc2Connection.&lt;init&gt;(AbstractJdbc2Connection.java:136)
  ...............
  
  Caused by: java.net.NoRouteToHostException: No route to host
          at java.net.PlainSocketImpl.socketConnect(Native Method)
          at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
          at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
          at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
  </code></pre>
  
  <p>Any help appreciated.</p>