Docker backup – Easy steps to backup and restore your containers
Disasters cannot be predicted or prevented, but you can always quickly bounce back from them if you maintain adequate backup plans for your business.
That makes data backups indispensable for any online business. By reducing the time to restore a crashed business, backups help to save businesses and minimize the losses.
In Docker systems, containers are used to host applications or services. Today, we’ll see how to perform docker backup and restore functions for containers.
In Docker, data is categorized into two – docker images for creating containers and the container data. The container data may be stored in containers or data volumes.
How to backup Docker containers
1. Before backing up a container, you need to identify its container ID. To know the container ID of a Docker instance, you can list the containers in that system.
The containers in a Docker machine can be listed using the command ‘docker ps’.
2. To backup a container in this list, use the ‘docker commit’ command with the following syntax:
docker commit -p container-ID backup-name
The container ID can be obtained from the ‘docker ps’ list and the ‘backup-name’ can be chosen based on your backup policy.
This snippet shows the docker backup of container ‘679facd4ee38’ (WordPress container), being taken in the name ‘backup-01’.
3. The backup image of the container, also known as ‘snapshot’, would be created with the name ‘backup-01’ and will be listed in the ‘docker images’ list:
This image of the container can be used to restore it on a later point and retrieve the state of the container to that moment this snapshot was taken.
4. It is not advisable to store the backups in the same Docker host machine as the container, as a hardware crash in it can tamper with the backups too.
So we usually convert these backup images to compressed formats such as ‘tar’ files and copy them over to an external server.
The ‘tar’ file for the backup image can be generated using the command:
docker save -o backup-name.tar backup-name
5. The tar file would be generated as shown, which can be copied over to external locations using ‘rsync’ or ‘scp’ tools.
Tools such as docker-backup can also be configured to take docker backup of containers. At Bobcares, we use custom scripts to perform backups.
The docker backup scripts are compiled based on parameters such as backup frequency, storage location, priority and importance of the container, etc.
[ Running a Docker infrastructure doesn’t have to be hard, or costly. Get world class Docker management services at affordable pricing. ]