3

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?

Community
  • 1
  • 1
Koningh
  • 628
  • 2
  • 8
  • 22

2 Answers2

4

Why does it not work?

Containers and host do not share their local IP stack. Thus, when you are within a container and try anything localhost:port the anything command will try to connect to the container-specific local IP stack, not the other container nor the host.

How to make it work?

Hard way: you either need to know the IP address of the other container and connect to this IP address..

Easier and cleaner way: .. either link your containers.

  --link=[]
      Add link to another container in the form of <name or id>:alias or just <name or id> in which case the alias will match the name

So you'll need to perform, assuming the camunda container is named camunda:

docker run -d --name app -p 3000:3000 --link camunda app

Then, once you docker-exec-ed into the container app you will be able to execute wget http://camunda:8080 -q -O - without error.


Note that while the linked containers graph cannot loop, e.g., camunda cannot be linked to app as you need to start a container to be able to link it, you actually do whatever you want/need playing with IP addresses. Note also that you can specify the IP address of a container using the --ip option (though it can only be used in conjunction with --net for user-defined networks).

Auzias
  • 3,638
  • 14
  • 36
  • Thanks to the answer given by Sebastian, I found the problem: Camunda is not available on the port (8000) I mapped it to when I started the container. So `wget http://camunda:8000 -q -O -` will not work, while `wget http://camunda:8080 -q -O -` does work. It would be nice to aceess camunda on a port I can pick myself, but I guess this is not possible when using linked containers. – Koningh Mar 09 '16 at 19:37
  • Sorry for the typos, I'll edit the post to match the port. You can pick the port yourself, why couldn't you? It is just a configuration matter. – Auzias Mar 10 '16 at 07:46
  • The standard camunda container exposes port 8080. So when I link my app container to the running camunda container, how can I achieve to have camunda available at port 8000 inside my app container? – Koningh Mar 10 '16 at 09:59
  • If the configuration does not offer to change this port you can: use [`socat`](http://www.dest-unreach.org/socat/), use a reverse proxy such as [`nginx`](http://nginx.com/) or even add a `iptable` or change the camunda source code as it is open source. – Auzias Mar 10 '16 at 12:07
  • 2
    The Camunda docker container your are using starts a tomcat server inside on which Camunda is deployed. If you want to change the port of the tomcat you can link your own configuration into the container. For example download this [server.xml](https://github.com/camunda/camunda-bpm-platform/blob/7.4.0/distro/tomcat/assembly/src/conf/server.xml) and change the port in line [96](https://github.com/camunda/camunda-bpm-platform/blob/7.4.0/distro/tomcat/assembly/src/conf/server.xml#L96). Then start the container with `-v PATH/TO/server.xml:/camunda/conf/server.xml`. – Sebastian Menski Mar 10 '16 at 13:05
1

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.

Soroush Chehresa
  • 5,490
  • 1
  • 14
  • 29
  • ¨camunda¨ stands for something specific? – Daniel Hernández Jun 08 '17 at 02:17
  • Nope, it's just the name of the docker container. Lets say you would start a container named _container2_ with the following --link option: `--link container1:otherapp`. Then, inside _container2_, you can access the app running in the container named _container1_ via `http://otherapp` on the port it runs at inside _container1_. – Koningh Jan 05 '18 at 09:04