Search code examples
dockerdocker-swarmdocker-stack

docker stack communicate between containers


I'm trying to setup a swarm using docker but I'm having issues with communicating between containers. I have cluster with 5 nodes. 1 manager and 4 workers.

3 apps: redis, splash, myapp

myapp has to be on the 4 workers

redis, splash just on the manager

myapp has to be able to communicate with redis and splash

I tried using the container name but its not working. It resolves the container name to different IPs.

ping splash # return a different ip than the container actually has

I am deploying running the swarm using docker stack

docker stack deploy -c docker-stack.yml myapp

Linking container between them also doesn't work. Any ideas ? Am I missing something ?

root@swarm-manager:~# docker version
Client:
 Version:      17.09.0-ce
 API version:  1.32
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:42:18 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.09.0-ce
 API version:  1.32 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:40:56 2017
 OS/Arch:      linux/amd64
 Experimental: false

docker-stack.yml contains:

version: "3"
services:
    splash:
        container_name: splash
        image: scrapinghub/splash
        ports:
            - 8050:8050
            - 5023:5023
        deploy:
            mode: global
            placement:
                constraints:
                    - node.role == manager

    redis:
        container_name: redis
        image: redis
        ports:
            - 6379:6379
        deploy:
            mode: global
            placement:
                constraints:
                    - node.role == manager

    myapp:
        container_name: myapp
        image: myapp_image:latest
        environment:
            REDIS_ENDPOINT: redis:6379
            SPLASH_ENDPOINT: splash:8050
        deploy:
            mode: global
            placement:
                constraints:
                    - node.role == worker
        entrypoint:
            - ping google.com

---- EDIT ----

I tried with curl also. Didn't work. docker stack deploy -c docker-stack.yml myapp

Creating network myapp_default
Creating service myapp_splash
Creating service myapp_redis
Creating service myapp_myapp

curl http://myapp_splash:8050

curl: (7) Failed to connect to myapp_splash port 8050: No route to host

curl http://splash:8050

curl: (7) Failed to connect to splash port 8050: No route to host

What worked is getting the actual container name of splash, which is some random generated string.

curl http://myapp_splash.d7bn0dpei9ijpba4q41vpl4zz.tuk1cimht99at9g0au8vj9lkz:8050

But this doesn't really help me.


Solution

  • I manage to get it working using curl http://tasks.splash:8050 or http://tasks.myapp_splash:8050.

    I don't know whats is causing this issue though. Feel free to comment with an answer.