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
Compare
docker-compose.ymlwithstack.ymlin yourorchestration-workshop-netdirectory 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
deploykey, children of which let us specify swarm-specific configurations. In this case, we set each service to DNSRR mode with the keyendpoint_mode: dnsrr. - Under the
webuiservice, 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
natnetwork with a customdockercoinsnetwork, which will get created as an overlay network connecting all the dockercoins containers across our swarm.
- When deploying as a stack, we can introduce the
Start our Services
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' dcCheck 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.0Notice the
REPLICAScolumn 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.Check out the details of the tasks running in your stack with
stack ps:PS: node-0 orchestration-workshop-net> docker stack ps dcThis shows the details of each running task scheduled by services in your stack, similar to
service ps, but for each service in the stack.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.