如何保存所有Docker映像并将其复制到另一台机器 [英] How to save all Docker images and copy to another machine

查看:825
本文介绍了如何保存所有Docker映像并将其复制到另一台机器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统中存在以下图像列表,并希望将所有这些图像复制到远程计算机上。

 存储库标记映像ID已创建虚拟尺寸
u14_py269最新6a1ec0b508b3 4天前885.9 MB
u12_py273最新c2a804894851 4天前686 MB
u12_core最新0d61eba80df2 4天前629.1 MB
c6dpy266 4天前1.32 GB
c6_core最新77c2ed19d87f 4天前1.278 GB
c7_py275最新bb1d3de68452 4天前1.117 GB
c7_core最新ca14a76e9cca 4天前1.081 GB
u14_py35最新d110c7e4a1f5之前914.5 MB
u14_py34最新085a37cb8614 5天前830.7 MB
u14_py276最新8927c6167930 5天前834.1 MB
u14_core最新93ead5abc25b 5天前776.9 MB
centos6 36877b5acebb 5天前228.9 MB
ubuntu最新36248ae4a9ac 5天前188 MB
ubuntu 12.04 94a7cb19a65b 5天前137.8 MB
edgester / gerrit最新ce4e3238052a 6天前735.2 MB
u14_as374_py276最新fa5fb7189d70 11天前1.497 GB
c721_as373_py1最新03 11天前844.3 MB
c721_as373_py35最新b5fece3dd45b 11天前1.127 GB
c171_con_core最新8af0d24a38a0 2周前377.2 MB
u14_as374_php55最新29df638e363a 3周前1.073 GB
j_u14_as374_php55最新29df638e363a 3周之前1.073 GB
centos centos7 c8a648134623 8周前196.6 MB
centos最新c8a648134623 8周前196.6
j_u14_as374_py276 10周前最新28f379d60882 871.5 MB
ubuntu 14.04 89d5d8e8bafb 10周前187.9 MB

当前,我正在使用保存并加载Docker映像,但我相信必须有一种更好的方法来处理所有映像。

解决方案

如果要一次导出所有图像,请创建一个大的tar文件:

  docker save $(docker images -q)-o /path/to/save/mydockersimages.tar 


如果要将多个图像保存在一个 .tar 文件中:

  IDS = $(泊坞窗图像| awk'{if($ 1〜/ ^(debian | centos)/)print $ 3}')
docker save $ IDS -o /path/to/save/somedockersimages.tar

最后,如果要导出多个图像,每个图像要包含一个 .tar 文件图像(磁盘效率不高:公共层保存在每个 .tar 文件中):

  docker图片| awk’{if($ 1〜/ ^(openshift | centos)/)打印$ 1 $ 2 $ 3}’| tr -c a-z A-Z0-9_.\n-% |同时读取REPOSITORY TAG IMAGE_ID 

echo ==保存$ REPOSITORY $ TAG $ IMAGE_ID ==
docker save -o / path / to / save / $ REPOSITORY- $ TAG- $ IMAGE_ID.tar $ IMAGE_ID
完成

您可能还想保存图像列表,以便可以标记还原的图像:

  docker images | sed 1d | awk’{print $ 1 $ 2 $ 3}’> mydockersimages.list 

在远程计算机上,您可以加载(导入)图像:

  docker load -i / path / to / save /mydockersimages.tar 

并标记导入的图像:

 读存储库标记IMAGE_ID 

回声 ==标记$ REPOSITORY $ TAG $ IMAGE_ID ==
码头标记 $ IMAGE_ID $ REPOSITORY:$ TAG
完成了< mydockersimages.list

有关保存/加载的更多信息,请阅读: 如何将Docker映像从一台主机复制到另一台主机使用存储库


I have the below list of images present on my system and want to copy all these images to a remote machine.

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
u14_py269           latest              6a1ec0b508b3        4 days ago          885.9 MB
u12_py273           latest              c2a804894851        4 days ago          686 MB
u12_core            latest              0d61eba80df2        4 days ago          629.1 MB
c6_py266            latest              cb1a94742d59        4 days ago          1.32 GB
c6_core             latest              77c2ed19d87f        4 days ago          1.278 GB
c7_py275            latest              bb1d3de68452        4 days ago          1.117 GB
c7_core             latest              ca14a76e9cca        4 days ago          1.081 GB
u14_py35            latest              d110c7e4a1f5        5 days ago          914.5 MB
u14_py34            latest              085a37cb8614        5 days ago          830.7 MB
u14_py276           latest              8927c6167930        5 days ago          834.1 MB
u14_core            latest              93ead5abc25b        5 days ago          776.9 MB
centos              centos6             36877b5acebb        5 days ago          228.9 MB
ubuntu              latest              36248ae4a9ac        5 days ago          188 MB
ubuntu              12.04               94a7cb19a65b        5 days ago          137.8 MB
edgester/gerrit     latest              ce4e3238052a        6 days ago          735.2 MB
u14_as374_py276     latest              fa5fb7189d70        11 days ago         1.497 GB
c721_as373_py275    latest              03ccf6961d0c        11 days ago         844.3 MB
c721_as373_py35     latest              b5fece3dd45b        11 days ago         1.127 GB
c171_con_core       latest              8af0d24a38a0        2 weeks ago         377.2 MB
u14_as374_php55     latest              29df638e363a        3 weeks ago         1.073 GB
j_u14_as374_php55   latest              29df638e363a        3 weeks ago         1.073 GB
centos              centos7             c8a648134623        8 weeks ago         196.6 MB
centos              latest              c8a648134623        8 weeks ago         196.6 MB
j_u14_as374_py276   latest              28f379d60882        10 weeks ago        871.5 MB
ubuntu              14.04               89d5d8e8bafb        10 weeks ago        187.9 MB

Currently I am using method suggested in save and load Docker images, but I believe there must be a better way to deal with all images.

解决方案

If you want to export all images at once, create one big tar file:

docker save $(docker images -q) -o /path/to/save/mydockersimages.tar

If you want to save multiples images in one .tar file:

IDS=$(docker images | awk '{if ($1 ~ /^(debian|centos)/) print $3}')
docker save $IDS -o /path/to/save/somedockersimages.tar

Finally, if you want to export multiple many images, with one .tar file per images (not disk efficient: common layer are saved in each .tar file):

docker images | awk '{if ($1 ~ /^(openshift|centos)/) print $1 " " $2 " " $3 }' | tr -c "a-z A-Z0-9_.\n-" "%" | while read REPOSITORY TAG IMAGE_ID
do
  echo "== Saving $REPOSITORY $TAG $IMAGE_ID =="
  docker  save   -o /path/to/save/$REPOSITORY-$TAG-$IMAGE_ID.tar $IMAGE_ID
done

You may also want to save the list of images so that the restored images can be tagged:

docker images | sed '1d' | awk '{print $1 " " $2 " " $3}' > mydockersimages.list

On the remote machine, you can load (import) the images:

docker load -i /path/to/save/mydockersimages.tar

and tag the imported images:

while read REPOSITORY TAG IMAGE_ID
do
        echo "== Tagging $REPOSITORY $TAG $IMAGE_ID =="
        docker tag "$IMAGE_ID" "$REPOSITORY:$TAG"
done < mydockersimages.list

For more information about save/load, read: How to copy Docker images from one host to another without using a repository

这篇关于如何保存所有Docker映像并将其复制到另一台机器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆