How to backup/restore docker image for deployment?

2020-05-13 16:15发布

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.

标签: docker
2条回答
三岁会撩人
2楼-- · 2020-05-13 16:17

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

查看更多
再贱就再见
3楼-- · 2020-05-13 16:36

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"

查看更多
登录 后发表回答