如何在不使用存储库的情况下将Docker映像从一台机器传输到另一台机器,无论是私有还是公共的?

我在VirtualBox中创建了自己的映像,完成后,我尝试部署到其他机器上以获得实际使用。

由于它基于我自己的镜像(如Red Hat Linux),因此无法从Dockerfile中重新创建。我的dockerfile不容易移植。

有没有简单的命令可以使用?还是另一种解决方案?


当前回答

所有其他答案都非常有用。我刚刚解决了同样的问题,并找到了一个使用docker机器scp的简单方法。

从Docker Machine v0.3.0开始,引入scp将文件从一台Docker机器复制到另一台。如果您想将文件从本地计算机复制到远程Docker机器(如AWS EC2或Digital Ocean),这非常方便,因为Docker机器正在为您处理SSH凭据。

使用docker保存图像,如:docker save-o docker-images.tar应用程序web使用docker machine scp复制图像码头机scp/docker-images.tar远程计算机:/home/ubuntu

假设您的远程Docker机器是远程机器,您希望tar文件所在的目录是/home/ubuntu。

加载Docker映像docker机器ssh远程机器sudo docker加载-i docker-images.tar

其他回答

您可以将一行代码与DOCKER_HOST变量一起使用:

docker save app:1.0 | gzip | DOCKER_HOST=ssh://user@remotehost docker load

使用docker机器时,您可以使用以下方式在机器mach1和mach2之间复制图像:

docker $(docker-machine config <mach1>) save <image> | docker $(docker-machine config <mach2>) load

当然,您也可以将pv放在中间以获得进度指示器:

docker $(docker-machine config <mach1>) save <image> | pv | docker $(docker-machine config <mach2>) load

您还可以省略docker机器配置子shell之一,以使用当前默认的docker主机。

docker save <image> | docker $(docker-machine config <mach>) load

将图像从当前docker主机复制到mach

or

docker $(docker-machine config <mach>) save <image> | docker load

从mach复制到当前docker主机。

执行Docker保存和加载功能的脚本(已试用):

Docker保存:

#!/bin/bash

#files will be saved in the dir 'Docker_images'
mkdir Docker_images
cd Docker_images
directory=`pwd`
c=0
#save the image names in 'list.txt'
doc= docker images | awk '{print $1}' > list.txt
printf "START \n"
input="$directory/list.txt"
#Check and create the image tar for the docker images
while IFS= read -r line
do
     one=`echo $line | awk '{print $1}'`
     two=`echo $line | awk '{print $1}' | cut -c 1-3`
     if [ "$one" != "<none>" ]; then
             c=$((c+1))
             printf "\n $one \n $two \n"
             docker save -o $two$c'.tar' $one
             printf "Docker image number $c successfully converted:   $two$c \n \n"
     fi
done < "$input"

Docker加载:

#!/bin/bash

cd Docker_images/
directory=`pwd`
ls | grep tar > files.txt
c=0
printf "START \n"
input="$directory/files.txt"
while IFS= read -r line
do
     c=$((c+1))
     printf "$c) $line \n"
     docker load -i $line
     printf "$c) Successfully created the Docker image $line  \n \n"
done < "$input"

您需要将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