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

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

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

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


当前回答

执行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"

其他回答

我假设您需要保存图像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映像保存到压缩存档中:

docker save <docker image name> | gzip > <docker image name>.tar.gz

然后使用以下命令将导出的图像加载到Docker:

zcat <docker image name>.tar.gz | docker load

我想移动所有带标签的图像。

```
OUT=$(docker images --format '{{.Repository}}:{{.Tag}}')
OUTPUT=($OUT)
docker save $(echo "${OUTPUT[*]}") -o /dir/images.tar
``` 

说明:

First OUT获取所有标记,但用新行分隔。第二个OUTPUT获取数组中的所有标记。第三个$(echo“${OUTPUT[*]}”)为单个docker save命令放置所有标记,以便所有图像都在一个tar中。

此外,这可以使用gzip压缩。在目标上运行:

tar xvf images.tar.gz -O | docker load

-tar的O选项将内容放在stdin上,docker加载可以获取这些内容。

您可以使用sshfs:

$ sshfs user@ip:/<remote-path> <local-mount-path>
$ docker save <image-id> > <local-mount-path>/myImage.tar

Run

docker images

以查看主机上的图像列表。假设您有一个名为awesome酱的图像。在终端中,cd到要导出图像的目录。现在运行:

docker save awesomesauce:latest > awesomesauce.tar

将tar文件复制到拇指驱动器或其他任何位置,然后将其复制到新的主机。

现在从新主机开始:

docker load < awesomesauce.tar

现在去喝杯咖啡,看看黑客新闻。。。