Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to backup/restore docker image for deployment?

Tags:

docker

I have an image to be updated with following command before each deployment.

$docker pull myusername/myproject:latest 

This command overwrites the previous image. How can I backup this image (or change it to a different tag locally without committing to networking repository? If there is anything wrong, I can restore the backup.

like image 998
Mr.Wang from Next Door Avatar asked Nov 03 '14 03:11

Mr.Wang from Next Door


People also ask

How do I restore and save an image in docker?

Restore your dataUse docker pull to restore images you pushed to Docker Hub. If you backed up your images to a local tar file, use docker image load -i images. tar to restore previously saved images. Re-create your containers if needed, using docker run , or Docker Compose.

Can I backup a docker container?

back up docker containers by exporting the docker container file system as a tar archive using the docker export command. You can later on create a new docker image from that tar archive with the docker import command.


2 Answers

How can I backup this image

Simply use the docker save command. $ docker save myusername/myproject:latest | gzip -c > myproject_img_bak20141103.tgz

You will later be able to restore it with the docker load command. gunzip -c myproject_img_bak20141103.tgz | docker load


or change it to a different tag locally without committing to networking repository?

Use the docker tag command: $ docker tag myusername/myproject:latest myusername/myproject:bak20141103

like image 81
Thomasleveil Avatar answered Sep 20 '22 05:09

Thomasleveil


For completeness: For Docker on Windows the following syntax applies:

docker save -o container-file-name.tar mcr.microsoft.com/windows/nanoserver:1809

docker load -i "c:\path\to\file.tar"

like image 35
silent Avatar answered Sep 22 '22 05:09

silent