How to take backup of docker container ?
In this post, we will look how to take backup of a docker container.
We can take backup in two steps:
a. First saving the container data into an image.
b. Saving the new image into TAR file.
1. Save Container data into an image.
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE phpmyadmin phpmyadmin 5622104ad36d 22 hours ago 370MB $ docker ps --all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 899d5bacbeb1 5622104ad36d "php_container1" 22 hours ago Created frosty_panini $ docker commit -p 899d5bacbeb1 php_container_backup sha256:64fb7636f6b9b594d5e6b7f6f3439d177758d4ec84789080e679d791d9bef7e1
2. Save the new image into TAR file.
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE php_container_backup latest 64fb7636f6b9 3 seconds ago 370MB phpmyadmin phpmyadmin 5622104ad36d 22 hours ago 370MB $ docker save 64fb7636f6b9 > /tmp/php_container_backup.tar $ ls -l /tmp/php_container_backup.tar -rw-r--r-- 1 saket wheel 378963968 Jan 17 02:21 /tmp/php_container_backup.tar $ du -sh /tmp/php_container_backup.tar 361M /tmp/php_container_backup.tar $