Docker - Tomcat and PostgreSQL containers in same host - No Route to host -


I have a web application running on Tomcat and has started the container using the command,

  Docker run -d -p 8080: 8080 tveuser / tve-repository: tve-services  

I also run a PostgreSQL container on the same host using the following command am:

  Docker run-D-P 80: 80-P-5432: 5432 Tivejhr / Tive-repository: TV-post-Jiaracl  

I Verify that PostgreSQL is running using phpPgAdmin but Neither could it find the tomato to connect. 'Docker PS' also tells me that both the containers are up and running.

I connect the web entry to the database through the TOKamet Reference.XML which contains the entry

  & lt; Parameter Name = "abc.connection.url" value = "jdbc: postgresql: //1.2.3.4: 5432 / dbname" />  

Where 1.2.3.4 is the Dockers Host IP in which the Container is Running. But when I run the Tomcat Container, I get the following error:

  Org.postgresql.util.PSQLException: The connection attempt failed. On Org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl (org.postgresql.core.ConnectionFactory.openConnection) (on org.postgresql.jdbc2.AbstractJdbc2Conction.on.on.phone.openConnectionImpl) and lt; Init & gt; (Org.postgresql.core.v3.ConnectionFactoryImpl.java. AbstractJdbc2Connection.java:136) caused by ...............: java.net.NoRouteToHostException: hosting on java.net No Route For PlainSocketImpl.socketConnect (Basic Method) Java.net.AbstractPlainSocketImpl.connectToAddress (java.net20000) on java.net java.net.AbstractPlainSocketImpl.connect (abstraplesssat utpl.javaela2) on AbstractionSnocSocket Impl.Denconnect (abstractplanssocket estimates.javaver 9 9) )  

Any help appreciated.

TL; DR : Firewall Czech Your host

You have been exposed to Postgrers which you Postgrejh container must connect to the IP address of your host at port, rather than the container dock IP Address.

Example,

  & lt; Parameter Name = "abc.connection.url" value = "jdbc: postgresql: //192.168 .xx: 5432 / dbname" />   

You will also need to configure PostGrace inside your Postgractor Docker Container to listen for connections other than 127.0.0.1 , which is the default .

Example, pg_hba.conf :

  Host all 0.0.0.0/0 md5  

Example tells Postgre to accept incoming connections from any IP address (you probably want to do something like 192.168.0.0/16 .

The value of postgres.conf in the listen_addresses will be changed:

  listen_addresses = '*' # to listen to the IP address (s);  

Once you make these configuration changes, you can see that B What PostgreSQL is listening to all requests from all IP within their Docker containers:

  netstat -tunlp active Internet connections (only servers) Proto Rikv-Q Bejen- a Local Address Foreign Address State PID Name of the program / TCP 0 0.0.0.0:5432 0.0.0.0:* LISTEN 816 / Postgrers TCP6 0 0 ::: 5432 ::: * Liston 816 / Postgrad  

And then from your host, make sure you can telnet in port 5432:

  Trying 192.168.xx 5432 192.168.xx .. 1982. Escape character '^]' is  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -