title: docker stack communicate between containers
body: <p>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.</p>
  
  <p>3 apps: redis, splash, myapp</p>
  
  <p>myapp has to be on the 4 workers</p>
  
  <p>redis, splash just on the manager</p>
  
  <p>myapp has to be able to communicate with redis and splash</p>
  
  <p>I tried using the container name but its not working. It resolves the container name to different IPs.</p>
  
  <p><code>ping splash # return a different ip than the container actually has</code></p>
  
  <p>I am deploying running the swarm using <code>docker stack</code></p>
  
  <p><code>docker stack deploy -c docker-stack.yml myapp</code></p>
  
  <p>Linking container between them also doesn't work.
  Any ideas ? Am I missing something ?</p>
  
  <pre><code>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
  </code></pre>
  
  <p>docker-stack.yml contains:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>---- EDIT ----</p>
  
  <p>I tried with curl also. Didn't work.
  <code>docker stack deploy -c docker-stack.yml myapp</code></p>
  
  <pre><code>Creating network myapp_default
  Creating service myapp_splash
  Creating service myapp_redis
  Creating service myapp_myapp
  </code></pre>
  
  <p><code>curl http://myapp_splash:8050</code></p>
  
  <p><code>curl: (7) Failed to connect to myapp_splash port 8050: No route to host</code></p>
  
  <p><code>curl http://splash:8050</code></p>
  
  <p><code>curl: (7) Failed to connect to splash port 8050: No route to host</code></p>
  
  <p>What worked is getting the actual container name of splash, which is some random generated string.</p>
  
  <p><code>curl http://myapp_splash.d7bn0dpei9ijpba4q41vpl4zz.tuk1cimht99at9g0au8vj9lkz:8050</code></p>
  
  <p>But this doesn't really help me.</p>