top of page
Writer's pictureSiddhesh Kadam

Docker Backup & Restoration




It is always recommended to take the backup of Docker container periodically to minimize the downtime window in case of Disaster Recovery.


Docker also has built in utility to take the backup of container.


How to take backup of container ?


First identify IMAGE ID of container of which backup needs to be taken.


[root@siddhesh ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               latest              4cdbec704e47        8 days ago          98.2MB
nginx               latest              ed21b7a8aee9        8 days ago          127MB
centos              latest              470671670cac        2 months ago        237MB
[root@siddhesh ~]#

So I have two container with IMAGE ID of 4cdbec704e47 / ed21b7a8aee9 / 470671670cac


To take the backup of container we can use docker commit. So here I am going to take the backup of nginx container.


[root@siddhesh ~]# docker commit -p  4ef2055b2bf6 nginx_backup_v1
sha256:44fa6bbbddc5038e3841684b25692caaa49486f5a96f84c9c49ffae0cf2fa173
[root@siddhesh ~]#

To verify you can run following command :


[root@siddhesh ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx_backup_v1     latest              44fa6bbbddc5        6 seconds ago       127MB
redis               latest              4cdbec704e47        8 days ago          98.2MB
nginx               latest              ed21b7a8aee9        8 days ago          127MB
centos              latest              470671670cac        2 months ago        237MB
[root@siddhesh ~]#

By using this method we can host backup of container on same server but it is not recommended to host the backup on same server. So using docker we can export backup in compress format like .tar


[root@siddhesh ~]# docker save -o nginx_backup_v1.tar nginx_backup_v1
[root@siddhesh ~]# file nginx_backup_v1.tar
nginx_backup_v1.tar: POSIX tar archive
[root@siddhesh ~]#

You can copy this image to your backup server using rsync or scp.


How to restore image from backup ?


To restore the docker container you run docker load command.


[root@siddhesh ~]# docker load -i nginx_backup_v1.tar
5f31356be213: Loading layer  6.656kB/6.656kB
Loaded image: nginx_backup_v1:latest
[root@siddhesh ~]#





Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page