如何在不使用存储库的情况下将Docker映像从一台机器传输到另一台机器,无论是私有还是公共的?
我在VirtualBox中创建了自己的映像,完成后,我尝试部署到其他机器上以获得实际使用。
由于它基于我自己的镜像(如Red Hat Linux),因此无法从Dockerfile中重新创建。我的dockerfile不容易移植。
有没有简单的命令可以使用?还是另一种解决方案?
如何在不使用存储库的情况下将Docker映像从一台机器传输到另一台机器,无论是私有还是公共的?
我在VirtualBox中创建了自己的映像,完成后,我尝试部署到其他机器上以获得实际使用。
由于它基于我自己的镜像(如Red Hat Linux),因此无法从Dockerfile中重新创建。我的dockerfile不容易移植。
有没有简单的命令可以使用?还是另一种解决方案?
当前回答
1.从注册表中提取图像或存储库。
docker pull[选项]名称[:TAG|@DIGEST]
2.将其保存为.tar文件。
docker save[选项]图像[图像…]
例如:
docker pull hello-world
docker save -o hello-world.tar hello-world
其他回答
真实世界示例
#host1
systemctl stop docker
systemctl start docker
docker commit -p 1d09068ef111 ubuntu001_bkp3
#create backup
docker save -o ubuntu001_bkp3.tar ubuntu001_bkp3
#upload ubuntu001_bkp3.tar to my online drive
aws s3 cp ubuntu001_bkp3.tar s3://mybucket001/
#host2
systemctl stop docker
systemctl start docker
cd /dir1
#download ubuntu001_bkp3.tar from my online drive
aws s3 cp s3://mybucket001/ubuntu001_bkp3.tar /dir1
#restore backup
cat ./ubuntu001_bkp3.tar | docker load
docker run --name ubuntu001 -it ubuntu001_bkp3:latest bash
docker ps -a
docker attach ubuntu001
我假设您需要保存图像id为7ebc8510bc2c的couchdb盒带:
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
将archiveName图像保存到tar文件。我将使用/media/sf_docker_vm/保存图像。
stratos@Dev-PC:~$ docker save imageID > /media/sf_docker_vm/archiveName.tar
将archiveName.tar文件复制到新的Docker实例中,使用任何在您的环境中有效的方法,例如FTP、SCP等。
在新的docker实例上运行docker load命令,并指定图像tar文件的位置。
stratos@Dev-PC:~$ docker load < /media/sf_docker_vm/archiveName.tar
最后,运行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
请查找此详细帖子。
要将图像从本地Docker安装传输到minikube VM:
docker save <image> | (eval $(minikube docker-env) && docker load)
dockerpushssh是我为这个场景创建的命令行实用程序。
它在服务器上建立一个临时的私有Docker注册表,从本地主机建立一个SSH隧道,推送映像,然后自行清理。
与docker save相比,这种方法的好处(在编写答案时,大多数答案都使用这种方法)是,只有新的层被推送到服务器,从而导致更快的上传。
通常,使用像dockerhub这样的中间注册表是不可取的,而且很麻烦。
https://github.com/brthor/docker-push-ssh
安装:
pip install docker-push-ssh
例子:
docker推ssh-i~/my_shkeyusername@myserver.com我的码头工人形象
最大的警告是,您必须手动将本地主机添加到Docker的insecure_registrys配置中。运行该工具一次,它会给您一个信息性错误:
Error Pushing Image: Ensure localhost:5000 is added to your insecure registries.
More Details (OS X): https://stackoverflow.com/questions/32808215/where-to-set-the-insecure-registry-flag-on-mac-os
我应该在Mac OS上的何处设置“--不安全注册表”标志?
1.从注册表中提取图像或存储库。
docker pull[选项]名称[:TAG|@DIGEST]
2.将其保存为.tar文件。
docker save[选项]图像[图像…]
例如:
docker pull hello-world
docker save -o hello-world.tar hello-world