How to Backup a Docker Container

Welcome to my Docker Tutorial for Beginners. On this article, I am going to show you how to Backup a Docker Container. To back up a container, we are going to use the commit command in Docker. The commit command will attempt to create a new image from a container. So, let’s get started. 

Back up a Docker Container

First, let’s check or list our containers 

docker ps

Output

As you can see I have three containers running on my Docker system. For example, I am going to back up the mysql-server container into mysql-server-backup01 image. 

docker commit -p mysql-server mysql-server-backup01

Output:

dhani@dhani-ThinkPad-T420:~/Documents$ docker commit -p mysql-server mysql-server-backup01
sha256:7bec5d8829e5b4548b0862bed5ae19b25802b2a13bed0253e501e895bd4bab2d

Now let’s check the image list

docker image ls

Output:

As you can see, now I have a new image called mysql-server-backup01. This is the backup image I just created. 

In case you want to copy or move the image to somewhere else, we can create a compressed image with this command

docker save -o ~/mysql-server-backup01.tar mysql-server-backup01

The command will create a tar file from my mysql-server-backup01 docker image to my home directory. Now I can move this tar file to another computer and re-deploy the image there.

How to Restore from Docker Backup

For example, I moved the  .tar backup file to another computer or another Docker host. I can simply use the following command to recover from the .tar file.

docker load -i mysql-server-backup01.tar

Now confirm and check with docker images command

docker images

Make sure the image is there.

Be the first to comment

Leave a Reply