Dockerized Java program can’t access other Docker container in network

  docker, docker-networking

I am new to Docker networking, but I’ve managed to set up a network which contains two running containers, with IP addresses specified by the --ip flag.

Create network:
docker network create --subnet=172.18.0.0/16 myNetwork

Start first container on network:
nohup docker run --net myNetwork --ip 172.18.0.22 container1 &

Start second container on network:
nohup docker run --net myNetwork --ip 172.18.0.23 container2 &

I can check network inspect and I see that both of my containers are present in the network with their specified IP addresses. Within container2, I can also ping container1 with telnet 172.18.0.22 7200 (I have a database running on port 7200 in container1).

However, I have a .jar file that runs within container2 launched with this line in the Dockerfile:
ENTRYPOINT java -jar /shared/myJar. The .jar contains code to hit the database in container1, however it hangs and can’t connect. I’m confused as to why it can’t connect since I am able to ping the port with telnet and see both of the containers running within my Docker network.

The only thing I can think of right now is whether the .jar is being restricted by the firewall and I need to open something up in IpTables, but I don’t see why that rule would be there by default…

Source: Docker Questions

LEAVE A COMMENT