Docker Community Forums

Share and learn in the Docker community.

Linking problems between two tomcat containers

(Bp91) #1

Hi guys, maybe someone can help me. I have this problem:

I want to dockerize two web application running on the same tomcat and on the same machine. One of the two web app is connected to a MySQL database running on another machine.

I tried to do in this way:

  • External MySQL database running on the previous server
  • two web apps running with docker ( two different docker container with tomcat)
  • nginx as reverse proxy
  • docker-compose for manage them

One app calls a service exposed by the other one. The url is given as a property (before I have for example with -Dapp1.url=

Now, with socket, I don’t know the ip of the app1 container. So, with nginx as reverse proxy, I tried to modify the property as -Dapp1.url=http://localhost:9090/app1/api (nginx is listening on port 9090 and on /app1 knows that has to serve the app1 container). But In my logs, I have “Connection refused” maybe because localhost inside the container is the IP of the container. But I have to reach the other app. Anyone can help me?

(Caldarolad) #2

You have a couple options.

You can set up your nginx to connect to the IP/port of the container (but this will change everytime you restart)

You can put nginx on a container, and make sure they’re all running on the same network, so nginx can call the containers directly by name, and not IP.

Or you can just make sure the containers are running on the same network. Then the containers can call each directly without going through a reverse proxy.

Look up
docker network create

Hope this helps