title: Deploy app on a cluster but cannot access it successfully
body: <p>I'm now learning to use docker follow <a href="https://docs.docker.com/get-started/part4/" rel="noreferrer">get-started documents</a>, but in part 4--Swarms I've met some problem. That is when deployed my app on a cluster, I cannot access it successfully.</p>
  
  <pre><code>docker@myvm1:~$ docker stack ps getstartedlab
  ID                  NAME                  IMAGE                     NODE                DESIRED STATE       CURRENT STATE              ERROR               PORTS
  gsueb9ejeur5        getstartedlab_web.1   zhugw/get-started:first   myvm1               Running             Preparing 11 seconds ago
  ku13wfrjp9wt        getstartedlab_web.2   zhugw/get-started:first   myvm2               Running             Preparing 11 seconds ago
  vzof1ybvavj3        getstartedlab_web.3   zhugw/get-started:first   myvm1               Running             Preparing 11 seconds ago
  lkr6rqtqbe6n        getstartedlab_web.4   zhugw/get-started:first   myvm2               Running             Preparing 11 seconds ago
  cpg91o8lmslo        getstartedlab_web.5   zhugw/get-started:first   myvm2               Running             Preparing 11 seconds ago
  
  docker@myvm1:~$ curl 'http://localhost'
  curl: (7) Failed to connect to localhost port 80: Connection refused
  
  ➜  ~ docker-machine ls
  NAME    ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
  myvm1   -        virtualbox   Running   tcp://192.168.99.101:2376           v17.06.0-ce
  myvm2   -        virtualbox   Running   tcp://192.168.99.100:2376           v17.06.0-ce
  
  ➜  ~ curl 'http://192.168.99.101'
  curl: (7) Failed to connect to 192.168.99.101 port 80: Connection refused
  </code></pre>
  
  <p>What's wrong?</p>
  
  <p>In addition, very strange. After adding below content in <code>docker-compose.yml</code> I found above question resolved automatically</p>
  
  <pre><code>visualizer:
      image: dockersamples/visualizer:stable
      ports:
        - "8080:8080"
      volumes:
        - "/var/run/docker.sock:/var/run/docker.sock"
      deploy:
        placement:
          constraints: [node.role == manager]
      networks:
        - webnet
  </code></pre>
  
  <p>but this time the new added <code>visualizer</code> does not work</p>
  
  <pre><code>docker@myvm1:~$ docker stack ps getstartedlab
  ID                  NAME                         IMAGE                             NODE                DESIRED STATE       CURRENT STATE             ERROR               PORTS
  xomsv2l5nc8x        getstartedlab_web.1          zhugw/get-started:first           myvm1               Running             Running 7 minutes ago
  ncp0rljod4rc        getstartedlab_visualizer.1   dockersamples/visualizer:stable   myvm1               Running             Preparing 7 minutes ago
  hxddan48i1dt        getstartedlab_web.2          zhugw/get-started:first           myvm2               Running             Running 7 minutes ago
  dzsianc8h7oz        getstartedlab_web.3          zhugw/get-started:first           myvm1               Running             Running 7 minutes ago
  zpb6dc79anlz        getstartedlab_web.4          zhugw/get-started:first           myvm2               Running             Running 7 minutes ago
  pg96ix9hbbfs        getstartedlab_web.5          zhugw/get-started:first           myvm2               Running             Running 7 minutes ago
  </code></pre>
  
  <p>from above you know it's always preparing.</p>
  
  <hr>
  
  <p>My whole docker-compose.yml </p>
  
  <pre><code>version: "3"
  services:
    web:
      # replace username/repo:tag with your name and image details
      image: zhugw/get-started:first
      deploy:
        replicas: 5
        resources:
          limits:
            cpus: "0.1"
            memory: 50M
        restart_policy:
          condition: on-failure
      ports:
        - "80:80"
      networks:
        - webnet
    visualizer:
      image: dockersamples/visualizer:stable
      ports:
        - "8080:8080"
      volumes:
        - "/var/run/docker.sock:/var/run/docker.sock"
      deploy:
        placement:
          constraints: [node.role == manager]
      networks:
        - webnet
  networks:
    webnet:
  </code></pre>