Working with Docker Swarm

Hands-On Lab

 

Photo of Travis Thomsen

Travis Thomsen

Course Development Director in Content

Length

01:00:00

Difficulty

Intermediate

The student will be tasked to work with Docker and configure one management node and one client node, with the Docker service running. They will then need to add the client node to a swarm cluster and work with services across the swarm.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Working with Docker Swarm

Introduction

In this hands-on lab, we will work with Docker and configure one management node and one client node, with the Docker service running. We will then add the client node to a swarm cluster and work with services across the swarm.

Solution

Open two terminal sessions, and log in to both servers via SSH using the credentials provided on the lab page:

ssh cloud_user@<PUBLIC_IP_ADDRESS>

Then, become the root user in each terminal:

sudo su -

Initialize Your Master Node

  1. In the first terminal, initialize the swarm master:

    docker swarm init
  2. Copy the docker swarm join command in the output.

Register Your Node with the Swarm Master

  1. In the second terminal, paste and enter the docker swarm join command from the above steps.

Create the Service in Your Swarm

  1. In the first terminal, download the image you plan to work with:

    docker pull httpd
  2. Now, create the service:

    docker service create --name our_api --replicas=2 httpd:latest

Conclusion

Congratulations on completing this hands-on lab!