Dockercoins On Swarm

By the end of this exercise, you should be able to:

  • Deploy an application on swarm as a 'stack', using a docker compose file
  • Get some high-level monitoring information about the services and tasks running as part of a stack

Prepare Images and Stack File

  1. Compare docker-compose.yml with stack.yml in your orchestration-workshop-net directory you cloned in the 'Starting a Compose App' exercise. They're very similar, but with a couple of important differences:

    • When deploying as a stack, we can introduce the deploy key, children of which let us specify swarm-specific configurations. In this case, we set each service to DNSRR mode with the key endpoint_mode: dnsrr.
    • Under the webui service, we need to set host mode port forwarding so our web frontend container can receive traffic forwarded from a host port.
    • Finally, we replace the default single-node nat network with a custom dockercoins network, which will get created as an overlay network connecting all the dockercoins containers across our swarm.

Start our Services

  1. Now that everything is prepped, we can start our stack. On node-0:

    PS: node-0 Administrator> cd ~/orchestration-workshop-net
    PS: node-0 orchestration-workshop-net> docker stack deploy -c='stack.yml' dc
    
  2. Check and see how your services are doing:

    PS: node-0 orchestration-workshop-net> docker stack services dc
    
    ID            NAME       MODE        REPLICAS  IMAGE                 
    0eqfdnr4nqp9  dc_redis   replicated  1/1       redis:3.2-nanoserver
    lfja33rybl9j  dc_worker  replicated  1/1       training/dc_worker:1.0
    sdobunv8m544  dc_webui   replicated  1/1       training/dc_webui:1.0
    sr5s4yu3u1lw  dc_hasher  replicated  1/1       training/dc_hasher:1.0
    uy9ztehqhgkw  dc_rng     replicated  1/1       training/dc_rng:1.0
    

    Notice the REPLICAS column in the output of above command; this shows how many of your desired replicas are running. At first, a few might show 0/1; before those tasks can start, the worker nodes will need to download the appropriate images from Docker Hub.

  3. Check out the details of the tasks running in your stack with stack ps:

    PS: node-0 orchestration-workshop-net> docker stack ps dc
    

    This shows the details of each running task scheduled by services in your stack, similar to service ps, but for each service in the stack.

  4. Determine the public IP and port Dockercoins' web UI is being served at, and visit it in your browser.

Conclusion

In this exercise, we stood up our first 'stack'. A stack is a collection of docker components (services, networks, volumes etc) that make up a full application, and we can create one directly from the same docker compose file we used to start an application on a single host using docker compose. A stack, however, will schedule workloads using swarm, distributed across our cluster.