Docker可移植性问题与本地保存的图像

我目前正在开发一个需要密封云基础架构的项目。 因此,所有人工制品,包括docker图像,都必须离线使用。

看起来, docker save和后续的docker import不会导致相等的docker图像。

Docker版本:1.10.3

 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES $ docker pull registry:2 2: Pulling from library/registry fdd5d7827f33: Pull complete a3ed95caeb02: Pull complete a79b4a92697e: Pull complete 6cbb75c7cc30: Pull complete 4831699594bc: Pull complete Digest: sha256:20f5d95004b71fe14dbe7468eff33f18ee7fa52502423c5d107d4fb0abb05c1d Status: Downloaded newer image for registry:2 $ docker run -p 5000:5000 -v /data/docker_images:/tmp/registry-dev registry:2 time="2016-04-01T19:11:55Z" level=warning msg="No HTTP secret provided - generated random secret. This may cause problems with uploads if multiple registries are behind a load-balancer. To provide a shared secret, fill in http.secret in the configuration file or set the REGISTRY_HTTP_SECRET environment variable." go.version=go1.5.3 instance.id=af87e7b7-9b56-49a6-bf71-4bd04e141c95 version=v2.3.1 time="2016-04-01T19:11:55Z" level=info msg="redis not configured" go.version=go1.5.3 instance.id=af87e7b7-9b56-49a6-bf71-4bd04e141c95 version=v2.3.1 time="2016-04-01T19:11:55Z" level=info msg="using inmemory blob descriptor cache" go.version=go1.5.3 instance.id=af87e7b7-9b56-49a6-bf71-4bd04e141c95 version=v2.3.1 time="2016-04-01T19:11:55Z" level=info msg="listening on [::]:5000" go.version=go1.5.3 instance.id=af87e7b7-9b56-49a6-bf71-4bd04e141c95 version=v2.3.1 time="2016-04-01T19:11:55Z" level=info msg="Starting upload purge in 45m0s" go.version=go1.5.3 instance.id=af87e7b7-9b56-49a6-bf71-4bd04e141c95 version=v2.3.1 

以上运行成功!

我的目标是将Docker Registry图像保存为* .tar文件,将其移动到另一台服务器上,将图像导入到那里,并能够在从Internet / Docker Hub中将其运行时尽可能运行Docker Registry。 下面是一系列命令,全部运行在同一台机器上,导致错误。

 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry 2 83139345d017 3 weeks ago 165.8 MB $ docker save 83139345d017 > registry.tar $ docker import registry.tar foo/registry sha256:8e84e7d07f97825b0ebaa04054f988566bb7b90083ba80caec6398e085adce84 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE foo/registry latest 8e84e7d07f97 3 seconds ago 172.3 MB registry 2 83139345d017 3 weeks ago 165.8 MB $ docker run -p 5000:5000 -v /data/tmp:/tmp/registry-dev foo/registry docker: Error response from daemon: No command specified. See 'docker run --help'. 

错误…它以某种方式期待一个命令,而直接从Docker Hub中拉出时,它不需要命令。 另外请注意,图像尺寸是几个不同的MB。

这是一个错误还是我想念这里的东西?

@larsks评论解决了它。 问题是我使用错误的function导入图像。 使用正确的函数是docker load

以下是适合于创build,移动和加载Docker镜像的一系列命令。

假设:

  • 本地Dockerregistry在IP 10.10.10.10:5000上运行
  • Docker Hub的Docker镜像被称为stack/overflow (这个镜像不存在!镜像名称仅用于说明。)

开始了…

 # Pull the image from public Docker Hub $ docker pull stack/overflow:0.9 # List the images $ docker images stack/overflow 0.9 57cbfaed16bf 7 months ago 20.96 MB # Change the name of the image to match your local Docker Registry address $ docker tag 57cbfaed16bf 10.10.10.10:5000/overflow:0.9 # Save Docker image # IMPORTANT: You need to use the "repo/tag" to select the image to be saved, as it otherwise does not save the "repo/tag" information in the tar file! $ docker save -o overflow.tar 10.10.10.10:5000/overflow:0.9 # Copy the overflow.tar file to the offline environment, which as the Docker Registry running on 10.10.10.10:5000 # Load Docker image $ docker load -i overflow.tar # List the images $ docker images 10.10.10.10:5000/overflow 0.9 38ea67f2e6d8 7 months ago 20.96 MB # Push the image to the local registry $ docker push 10.10.10.10:5000/overflow