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

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

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

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


当前回答

通过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

其他回答

根据@kolypto的回答,这对我来说很有用,但只适用于docker加载的sudo:

docker save <image> | bzip2 | pv | ssh user@host sudo docker load

或者如果您没有/不想安装pv:

docker save <image> | bzip2 | ssh user@host sudo docker load

无需手动压缩或类似操作。

您可以使用sshfs:

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

首先将Docker映像保存到压缩存档中:

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

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

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

通过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保存:

#!/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"