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

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

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

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


当前回答

真实世界示例

#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




其他回答

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

```
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加载可以获取这些内容。

保存所有图像的最佳方法如下:

docker save $(docker images --format '{{.Repository}}:{{.Tag}}') -o allimages.tar

以上代码将保存allimages.tar中的所有图像,要加载图像,请转到保存图像的目录并运行以下命令:

docker load -i allimages.tar

只需确保在PowerShell中而不是在Commad Prompt中使用此命令

Run

docker images

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

docker save awesomesauce:latest > awesomesauce.tar

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

现在从新主机开始:

docker load < awesomesauce.tar

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

执行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机器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