I am new to docker and I am trying to run a distributed JAVA application over docker swarm. I tested it on one node using the command docker-compose up and it works fine.
When I tried to deploy it as a service with the command
docker stack deploy --compose-file myfile.yml myapp
the component "im" is not able to connect with the component "orchestrator"
I use the label "orchestrator" as IP address for the component (it works with the simple compose up)
Any help? below my compose file
I have created a compose file:
version: "3"
services:
zk:
image: xxx/cep
deploy:
mode: replicated
replicas: 1
entrypoint: /ext-sw/zookeeper-3.4.5/bin/zkServer.sh
command: start-foreground
ports:
- 2181:2181
networks:
- cepnet
orchestrator:
image: xxx/cep
deploy:
mode: replicated
replicas: 1
entrypoint: /bin/runOrchestrator
ports:
- 9000:9000
depends_on:
- zk
networks:
- cepnet
im:
image: xxx/cep
deploy:
mode: replicated
replicas: 1
entrypoint: /bin/runIM -IP im -PORT 9901 -ID im1 -LOGID im1
ports:
- 9901:9901
depends_on:
- orchestrator
networks:
- cepnet
networks:
cepnet:
enter code here
EDIT: As said in comments my original problem was due to the IP assigned by docker to a container.
Below the output of the ping command run with the service name and hostname
root@90cfe6fc88ed:~# ping orchestrator
PING orchestrator (10.0.0.9) 56(84) bytes of data.
64 bytes from 10.0.0.9: icmp_seq=1 ttl=64 time=0.032 ms
64 bytes from 10.0.0.9: icmp_seq=2 ttl=64 time=0.034 ms
64 bytes from 10.0.0.9: icmp_seq=3 ttl=64 time=0.033 ms
^C
--- orchestrator ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2010ms
rtt min/avg/max/mdev = 0.032/0.033/0.034/0.000 ms
root@90cfe6fc88ed:~# ping $(hostname)
PING 90cfe6fc88ed (10.0.0.10) 56(84) bytes of data.
64 bytes from 90cfe6fc88ed (10.0.0.10): icmp_seq=1 ttl=64 time=0.055 ms
64 bytes from 90cfe6fc88ed (10.0.0.10): icmp_seq=2 ttl=64 time=0.018 ms
64 bytes from 90cfe6fc88ed (10.0.0.10): icmp_seq=3 ttl=64 time=0.014 ms
^C
--- 90cfe6fc88ed ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2033ms
rtt min/avg/max/mdev = 0.014/0.029/0.055/0.018 ms
As stated in the documentation depends_on
is not supported on swarm. Your application needs to be able to handle a situation where one service you depend on is not runninng (e.g try to reconnect until it becomes available)
If you want to test if this is really the issue wait for all services to run and then docker kill your service that had issues connecting. If it then runs fine its clearly a problem of it expecting the other service to already run.