Working with Docker Swarm

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

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.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Initialize your Master Node

Before you can create a service, you have to initialize the swarm master. You can accomplish this via:

docker swarm init

NOTE: Be sure to capture the output of the command so that you can use it on your node to register with the master!

Register Your Node with the Swarm Master

Once the master has been initialized, you will have captured the ‘join’ command containing the token you need. The command will look something like this. You will run the following command on the second server in your configuration:

docker swarm join --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2 192.168.99.121:2377

NOTE: Your token string AND IP will differ for your lab, this is an example of the command you will run

Create the Service in Your Swarm

Be sure you download the image you plan to work with:

docker pull httpd

Now, on the master server, you can run the following command to run your service:

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

This will create a service with two replicas, one running on each node in the swarm

Additional Resources

Your development team is now working on a new web application service and needs a basic cluster of web servers that they can throw load against in order to test performance.

As a result, you have been asked to provide a basic cluster that encompasses one management node and one client node. You will need to create the manager and join the client to the cluster and confirm they are all registered appropriately.

You have found a basic HTTPD image available on Docker Hub that is fine for this purpose called 'httpd'. Using that image, create a service called 'our_api' that runs across the cluster, making sure to redirect service HTTP port 80 to the underlying swarm port 80, using at least two replicas.

Once you confirm that two replicas are running, increase the replica count to four to be sure your cluster has sufficient capacity to scale. Once confirmed the replicas are running as expected, reduce the replica count back to two and you can turn the environment back over the development team to begin their work.

Escalate to root using sudo -i or sudo su -

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?