Initialize Swarm with `docker swarm init`.

Creating a service

Using `docker service create`, create a service from the image `traefik/whoami` accessible on port 9999 and connected to port 80 with 5 replicas.

Access your service and refresh the page several times. The displayed information changes. Why?

The example-voting-app stack

  1. Read the architecture schema of the example-voting-app on GitHub. Note that the worker service exists in two versions using different programming languages (Java or .NET), and all services have images for both Windows and Linux containers. These versions can be deployed interchangeably and do not change the functionality of the multi-container application. It's a demonstration of the usefulness of containerization paradigm and “micro-service” architecture.
  2. Carefully read the files docker-compose.yml, docker-compose-simple.yml, docker-stack-simple.yml, and docker-stack.yml. These are all classic Docker Compose files with different options related to deployment via Swarm. Which options seem specific to Docker Swarm? These options allow configuring orchestration features.
  3. Quickly draw the architecture schema associated with the `docker-compose-simple.yml` file, then the one associated with `docker-stack.yml`, indicating which service belongs to which network.
  4. With `docker swarm init`, transform your Docker installation into a Swarm-compatible installation. Read carefully the message returned to you.
  5. Deploy the stack from the `docker-stack.yml` file: docker stack deploy –compose-file docker-stack.yml vote.
  6. docker stack ls indicates 6 services for the`vote stack. Also observe the output of docker stack ps vote and `docker stack services vote`. What is a service in Swarm terminology?
  7. Access the different front-ends of the stack using the information from the previous commands. On the vote-linked front-end, refresh the page several times. What does the line “Processed by container ID […]” mean? Why does it vary?
  8. Scale the stack by adding replicas of the vote-linked front-end using `docker service –help`. Access this front-end and verify that it has worked by refreshing several times.

Clustering among friends

With a service
  1. Group in pairs or threes to create a cluster from your respective VMs (use a Swarm command to retrieve the necessary instructions).
  2. If grouping several VMs is not possible, you can create a multi-node cluster very simply with the interface of the Play With Docker site, you must log in with your Docker Hub credentials.
  3. You can run `docker swarm –help` to get missing information, or run `docker swarm leave –force` to reset your Docker Swarm configuration if necessary.
  4. Feel free to look in the logs with `systemctl status docker` how the node leader election is going, from the moment you have more than one manager.
  5. Launch the following service: `docker service create –name whoami –replicas 5 –publish published=80,target=80 traefik/whoami`.
  6. Access the service from one node, and from the other. Refresh the page several times. The displayed information changes. Which ones, and why?
With the example-voting-app stack
  1. If necessary, clone the repository of the example-voting-app application again with `git clone https://github.com/dockersamples/example-voting-app` and then deploy the stack of your choice.
  2. Add in the Compose file instructions to scale two services differently (3 replicas for the front-end service, for example). Don't forget to redeploy your Compose file.
  3. Then specify some orchestration options exclusive to Docker Swarm: what does `mode: global` do? Don't forget to redeploy your Compose file.
  4. With Portainer or with docker-swarm-visualizer, explore the cluster thus created (the `docker-stack.yml` file of the example-voting-app already contains a copy of docker-swarm-visualizer).
  5. Find the command to demote and promote one of your manager nodes to worker and vice versa.
  6. Then remove a node from the cluster (drain): docker node update –availability drain <node-name>.

Optional: debug the Docker config of example-voting-app

Did you notice? We successfully deployed a great voting application stack, but if you test the vote, you'll see that it doesn't work, it's not counted. Besides being a living plea against electronic voting, you could try to debug it now (it's pretty easy).

Solution / explanations:

Someone abandoned the Docker Hub repository linked to this app, and the person who has access to it is unreachable! It's a great example of the reality of the Docker ecosystem, and the fact that you should be wary of images created by others. Fortunately, it's just a matter of:

Introduction to Kubernetes

The `kube-deployment.yml` file of the example-voting-app describes the same app for deployment in Kubernetes rather than Docker Compose or Docker Swarm. Try to find some equivalences between Docker Compose / Swarm and Kubernetes by carefully reading this file describing a Kubernetes deployment.