Docker: how to backup and restore a swarm manager.

Docker manager nodes store the swarm state and manager logs in the /var/lib/docker/swarm/ directory, without the state you cannot restore the swarm. We don't need to take a backup from all swarm nodes since all should keep the same state.

To take a backup

sudo systemctl stop docker
sudo tar -zvcf backup.tar.gz -C /var/lib/docker/swarm .
sudo systemctl start docker

To restore from backup

sudo systemctl stop docker
sudo rm -rf /var/lib/docker/swarm/*
sudo tar -zxvf backup.tar.gz -C /var/lib/docker/swarm/
sudo systemctl start docker
docker node ls

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store