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

时间:2016-04-01 19:42:07

标签: docker docker-registry

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

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 文件,将其移动到另一台服务器,在那里导入映像,并且能够尽可能地运行Docker Registry是从Internet / Docker Hub中提取的。下面是命令序列,所有命令都运行在同一台机器上,导致错误。

$ 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不同。

这是一个错误还是我错过了什么?

1 个答案:

答案 0 :(得分:0)

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

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

假设:

  • 本地Docker注册表在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