Backing Up and Restoring a Docker Swarm

1.5 hours
  • 4 Learning Objectives

About this Hands-on Lab

For the last six months, the Acme Anvil Corporation has been migrating some of their bare metal infrastructure to Docker containers. A schism has developed between the members of your team on whether to use Docker Swarm or Kubernetes. To settle the dispute, your manager has decided to create a series of challenges. You have been tasked with creating a demo on how to back up and restore a Docker swarm. You are to set up a Docker swarm with 3 nodes, scale the backup service up to 3 nodes, and back up your master node and restore it to a backup instance.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Back up the swarm master.

Stop the docker service on the master node.

systemctl stop docker

Back up the /var/lib/docker/swarm/ directory.

systemctl stop docker
tar czvf swarm.tgz /var/lib/docker/swarm/
Restore the swarm on the backup master.

Copy the swarm backup from the master node to the backup master:

scp swarm.tar.tgz cloud_user@BACKUP_IP_ADDRESS:/home/cloud_user/

From the backup master, extract the backup file:

tar xzvf swarm.tar.tgz

Copy the swarm directory to /var/lib/docker/swarm:

cd /var/lib/docker
cp -rf swarm/ /var/lib/docker/

Reinitialize the swarm:

docker swarm init --force-new-cluster
Add the worker nodes to the restored cluster.

Remove each node from the old swarm:

docker swarm leave

Add each node to the backup swarm:

docker swarm join --token TOKEN IP_ADDRESS:2377
Distribute the replicas across the swarm.

Scale the replicas down to 1:

docker service scale backup=1

Next, scale the replicas up to 3 to distribute the replicas across the swarm:

docker service scale backup=3

Additional Resources

In this lab, you are tasked with backing up and restoring a Docker swarm.

  1. Use cat on the file swarm-token.txt to show the join token for your worker nodes.
  2. Add 2 worker nodes to the swarm.
  3. Scale the backup service up to 3 replicas.
  4. Stop the Docker service on the master node and use tar to compress the swarm directory.
  5. Use scp to securely copy the swarm tarball to /home/cloud_user on the backup master node.
  6. Use tar to extract the tarball.
  7. Stop the Docker service, restore the swarm directory, and start up the Docker service.
  8. Force the swarm to reinitialize a new cluster.
  9. Add the two worker nodes to the swarm.

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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

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