如何在不使用存储库的情况下将Docker映像从一台主机复制到另一台主机

本文翻译自:How to copy Docker images from one host to another without using a repository

How do I transfer a Docker image from one machine to another one without using a repository, no matter private or public? 如何在不使用存储库的情况下将Docker映像从一台计算机转移到另一台计算机,无论是私有的还是公共的?

I am used to play and create my own image in VirtualBox, and when it is finished, I try to deploy to other machines to have real usage. 我习惯于在VirtualBox中播放和创建自己的映像,完成后,我尝试部署到其他计算机上以实际使用。

Since it is based on own based image (like Red Hat Linux), it cannot be recreated from a Dockerfile. 由于它基于自己的映像(例如Red Hat Linux),因此无法从Dockerfile重新创建。

Are there simple commands I can use? 我可以使用简单的命令吗? Or another solution? 还是其他解决方案?

It seems save/export can achieve a similar purpose, see What is the difference between save and export in Docker? 看来保存/导出可以达到类似的目的,请参阅Docker中保存和导出之间有什么区别? , and I prefer the save command for my case. ,对于我的情况,我更喜欢使用save命令。


#1楼

参考:https://stackoom.com/question/1cQcf/如何在不使用存储库的情况下将Docker映像从一台主机复制到另一台主机


#2楼

For a flattened export of a container's filesystem, use; 要扁平导出容器的文件系统,请使用;

docker export CONTAINER_ID > my_container.tar

Use cat my_container.tar | docker import - 使用cat my_container.tar | docker import - cat my_container.tar | docker import - to import said image. cat my_container.tar | docker import -图像


#3楼

You will need to save the Docker image as a tar file: 您将需要将Docker映像另存为tar文件:

docker save -o <path for generated tar file> <image name>

Then copy your image to a new system with regular file transfer tools such as cp , scp or rsync (preferred for big files). 然后使用常规文件传输工具(例如cpscprsync (对于大文件而言首选))将映像复制到新系统。 After that you will have to load the image into Docker: 之后,您必须将映像加载到Docker中:

docker load -i <path to image tar file>

PS: You may need to sudo all commands. PS:您可能需要对所有命令进行sudo

EDIT: You should add filename (not just directory) with -o, for example: 编辑:您应该使用-o添加文件名(而不仅仅是目录),例如:

docker save -o c:/myfile.tar centos:16

#4楼

I assume you need to save couchdb-cartridge which has an image id of 7ebc8510bc2c: 我假设您需要保存其图片ID为7ebc8510bc2c的couchdb-cartridge

stratos@Dev-PC:~$ docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
couchdb-cartridge                      latest              7ebc8510bc2c        17 hours ago        1.102 GB
192.168.57.30:5042/couchdb-cartridge   latest              7ebc8510bc2c        17 hours ago        1.102 GB
ubuntu                                 14.04               53bf7a53e890        3 days ago          221.3 MB

Save the archiveName image to a tar file. 将archiveName图像保存到tar文件。 I will use the /media/sf_docker_vm/ to save the image. 我将使用/media/sf_docker_vm/保存图像。

stratos@Dev-PC:~$ docker save imageID > /media/sf_docker_vm/archiveName.tar

Copy the archiveName.tar file to your new Docker instance using whatever method works in your environment, for example FTP , SCP , etc. 使用环境中可用的任何方法将archiveName.tar文件复制到新的Docker实例中,例如FTPSCP等。

Run the docker load command on your new Docker instance and specify the location of the image tar file. 在新的Docker实例上运行docker load命令,并指定映像tar文件的位置。

stratos@Dev-PC:~$ docker load < /media/sf_docker_vm/archiveName.tar

Finally, run the docker images command to check that the image is now available. 最后,运行docker images命令以检查该映像现在是否可用。

stratos@Dev-PC:~$ docker images
REPOSITORY                             TAG        IMAGE ID         CREATED             VIRTUAL SIZE
couchdb-cartridge                      latest     7ebc8510bc2c     17 hours ago        1.102 GB
192.168.57.30:5042/couchdb-cartridge   latest     bc8510bc2c       17 hours ago        1.102 GB
ubuntu                                 14.04      4d2eab1c0b9a     3 days ago          221.3 MB

Please find this detailed post . 请找到这个详细的帖子


#5楼

Transferring a Docker image via SSH, bzipping the content on the fly: 通过SSH传输Docker映像,并即时bzip内容:

docker save <image> | bzip2 | \
     ssh user@host 'bunzip2 | docker load'

It's also a good idea to put pv in the middle of the pipe to see how the transfer is going: pv放在管道中间也是一个好主意,以查看传输的过程:

docker save <image> | bzip2 | pv | \
     ssh user@host 'bunzip2 | docker load'

(More info about pv : home page , man page ). (有关pv更多信息: 主页手册页 )。


#6楼

To save an image to any file path or shared NFS place see the following example. 要将图像保存到任何文件路径或共享NFS位置,请参见以下示例。

Get the image id by doing: 通过执行以下操作获取图像ID:

sudo docker images

Say you have an image with id "matrix-data". 假设您有一个ID为“矩阵数据”的图片。

Save the image with id: 保存具有ID的图片:

sudo docker save -o /home/matrix/matrix-data.tar matrix-data

Copy the image from the path to any host. 将映像从路径复制到任何主机。 Now import to your local Docker installation using: 现在,使用以下命令导入到本地Docker安装:

sudo docker load -i <path to copied image file>
发布了0 篇原创文章 · 获赞 73 · 访问量 55万+

猜你喜欢

转载自blog.csdn.net/w36680130/article/details/105267500