This post helps you to learn about the steps to take the backup (snapshot) and restore the docker Container. 

Steps for backup of Docker Container:

1. Convert the container details as an image using "commit",

 $ docker commit -p [container-id] testbackup

Now a new image testbackup will be created.This will not cover the data volume. If you need the data-volume, take the backup of data-volume separately.

You are able to get the data-directory (data volume location) of a container using the command ‘docker inspect container-name‘. You will get a section called “Mounts”. Location mentioned in “Source” is the data volume. You may directly backup this folder to get backup of data volume.

"Mounts": [
"Source": "/site",
"Destination": "/usr/xx/xxx/xxxs",
"Mode": "",
"RW": true,
"Propagation": "rprivate"

2. Save the image testbackup as tar file with the following command,

$ docker save -o testbackup.tar testbackup
$ ls -al
-rw------- 1 root root 178697728 Jul 13 11:59 testbackup.tar

You may choose to save the tar file on NFS mount point. Another option is directly pushing the image testbackup.tar  to your local registry. Before pushing the backup image, we need to tag it appropriately for identifaication.

$ docker tag testbackup localhost:8000/backup-image:v1.3.2

In the above example, hostname is localhost. Local registry is located and 8000 is the port number. You must change the hostname to point to the correct host. Note the repository and tag name, backup-image:ts in the example, must all be in lower case to be a valid tag.

 $ docker push backup-image:v1.3.2

Restoring a Docker Container:

1. For restoring Image can be extracted from backup tar file using the following command,

$ docker load -i /tmp/testbackup.tar

You can create container from this image using “docker run“. If you had data volume on the original container. You must restore the data volume too and run container with the data volume (docker run -v)

2. You have to pull it in-case of pushed image for restoring the data,

$ docker pull localhost:8000/backup-image:v1.3.2