Search code examples
node.jsdockercamunda

Access service running in docker container from inside another docker container


At the moment I'm running a node.js application inside a docker container which needs to connect to camunda, which runs in another container.

I start the containers with the following command

docker run -d --restart=always --name camunda -p 8000:8080 camunda/camunda-bpm-platform:tomcat-7.4.0
docker run -d --name app -p 3000:3000 app

Both applications are now running and I can access camunda by navigating to my host's IP on port 8000, and running wget http://localhost:8000 -q -O - also returns the camunda page. When I login to my app container with docker exec -it app sh and type wget http://localhost:8000 -q -O -, I cannot access camunda. Instead I get the following error:

 wget: can't connect to remote host (127.0.0.1): Connection refused

When I link my app container to the camunda container with --link camunda:camunda, and type wget http://camunda:8000 -q -O - in my app container, I get the following error:

wget: can't connect to remote host (172.17.0.4): Connection refused`

I've seen this option, so I started my app container with --add-host camunda:my_hosts_ip and tried wget again, resulting in:

 wget: can't connect to remote host (149.210.227.191): Operation timed out

When running wget http://149.210.227.191:5001 -q -O - on my host machine however, I get a correct response immediately.

Ideally I would like to just start my app container without the need to supply the external IP in any way, and let the app container just use the camunda service via the localhost or by linking the camunda container tot my app container. What would be the easiest way to achieve this?


Solution

  • Original answer below. Note that link has been deprecated and the recommended replacement is network. That is explained in the answer to this question: docker-compose: difference between network and link

    -- Use the --link camunda:camunda option for your app container. Then you can access camunda via http://camunda:8080/.... The link option adds a entry to the /etc/hosts file of the app container with the IP address of the camunda container. This also means you have to restart your app container if you restart the camunda container.