如何在不使用存储库的情况下将Docker映像从一台机器传输到另一台机器,无论是私有还是公共的?
我在VirtualBox中创建了自己的映像,完成后,我尝试部署到其他机器上以获得实际使用。
由于它基于我自己的镜像(如Red Hat Linux),因此无法从Dockerfile中重新创建。我的dockerfile不容易移植。
有没有简单的命令可以使用?还是另一种解决方案?
如何在不使用存储库的情况下将Docker映像从一台机器传输到另一台机器,无论是私有还是公共的?
我在VirtualBox中创建了自己的映像,完成后,我尝试部署到其他机器上以获得实际使用。
由于它基于我自己的镜像(如Red Hat Linux),因此无法从Dockerfile中重新创建。我的dockerfile不容易移植。
有没有简单的命令可以使用?还是另一种解决方案?
当前回答
您可以使用sshfs:
$ sshfs user@ip:/<remote-path> <local-mount-path>
$ docker save <image-id> > <local-mount-path>/myImage.tar
其他回答
通过gzip命令保存和加载docker图像的最快方法:
docker save <image_id> | gzip > image_file.tgz
要在另一台服务器上加载压缩图像,请立即使用此命令,它将被识别为压缩图像:
docker load -i image_file.tgz
要重命名或重新标记图像,请使用:
docker image tag <image_id> <image_path_name>:<version>
例如:
docker image tag 4444444 your_docker_or_harbor_path/ubuntu:14.0
首先将Docker映像保存到压缩存档中:
docker save <docker image name> | gzip > <docker image name>.tar.gz
然后使用以下命令将导出的图像加载到Docker:
zcat <docker image name>.tar.gz | docker load
您需要将Docker映像保存为tar文件:
docker save -o <path for generated tar file> <image name>
然后使用常规的文件传输工具(如cp、scp或rsync)将图像复制到新系统中(对于大文件更为理想)。之后,您必须将图像加载到Docker中:
docker load -i <path to image tar file>
PS:您可能需要sudo所有命令。
编辑:您应该使用-o添加文件名(而不仅仅是目录),例如:
docker save -o c:/myfile.tar centos:16
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