简体   繁体   English

Docker 保存/加载丢失原始图像存储库/名称/标签

[英]Docker save/load lose original image repository/name/tag

I'm using Docker 1.12.6.我正在使用 Docker 1.12.6。

I have pulled an image from the Docker registry.我从 Docker 注册表中提取了一个图像。 I have exported the images as tar files using the docker save command.我已使用docker save命令将图像导出为 tar 文件。

I removed the original image and container and loaded the exported image using docker load -i myImage.tar .我删除了原始图像和容器,并使用docker load -i myImage.tar加载了导出的图像。

Now, when running docker images I notice my image have lost its repository/tag information:现在,当运行docker images我注意到我的镜像丢失了它的存储库/标签信息:

    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              5fae4d4b9e02        8 weeks ago         581.3 MB

Why does it have this behavior and how do I keep the original image name?为什么它有这种行为,我如何保留原始图像名称?

Use采用

docker save -o filename.tar <repo>:<tag>

The command docker save <image id> removes the repository and tag names.命令docker save <image id>删除存储库和标签名称。

To solve this, use docker save <repo>:<tag> it will keep the repository and tag name in the saved file.要解决此问题,请使用docker save <repo>:<tag>它将存储库和标签名称保留在保存的文件中。 For example:例如:

docker save -o ubutu-18.04.tar ubuntu:18.04

I had the same problem, so then I used with the following command to fix it manually:我遇到了同样的问题,所以我使用以下命令手动修复它:

docker tag <Image-ID> <desired Name:Tag>

Reference 参考


[ NOTE ]: [注意]:

It's inconsistent: docker save image-repo-name -> docker load restores name, docker save SHA -> docker load no names or tags, docker save name:latest -> docker load no names or tags.不一致: docker save image-repo-name -> docker load restores name, docker save SHA -> docker load no names or tags, docker save name:latest -> docker load no names or tags.

AND :

The current (and correct) behavior is as follows:当前(和正确)的行为如下:

 docker save repo

Saves all tagged images + parents in the repo, and creates a repositories file listing the tags将所有标记的图像 + 父项保存在存储库中,并创建一个列出标记的存储库文件

docker save repo:tag

Saves tagged image + parents in repo, and creates a repositories file listing the tag将标记的图像 + 父项保存在 repo 中,并创建一个列出标记的存储库文件

docker save imageid

Saves image + parents, does not create repositories file.保存图像 + 父项,不创建存储库文件。 The save relates to the image only, and tags are left out by design and left as an exercise for the user to populate based on their own naming convention.保存仅与图像相关,标签被设计遗漏,留作练习,供用户根据自己的命名约定填充。

Reference参考

A single image ID can have multiple names/tags, so the way that you loose the the names and tags is what I would expect to happen after saving and loading the image to/from a tar ball.单个图像 ID可以有多个名称/标签,因此您丢失名称和标签的方式是我希望在将图像保存到 tar 球或从 tar 球加载图像后会发生的情况。

Mode details are in the discussion about it here模式的细节是关于它的讨论在这里

From docker documentation:来自 docker 文档:

cat exampleimage.tgz | cat exampleimage.tgz | docker import - exampleimagelocal:new docker 导入-exampleimagelocal:new

root@mymachine:/tmp# cat myimage.tar | docker import --message "New image imported from tarball" - reponame:my-image-name
sha256:be0794427222dcb81182a59c4664b350ecb5ffb7b37928d52d72b31
root@mymachine:/tmp# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
reponame          my-image-name    be0794427222        6 seconds ago       4.31GB

This one worked for me.这个对我有用。

This is a work around这是一个解决方法

  1. Go to source docker host machine, create text file containing all the image details using the following command docker image ls > images.txt转到源 docker 主机,使用以下命令docker image ls > images.txt创建包含所有图像详细信息的文本文件

  2. The above command will produce a text file similar to the following REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 293e4ed402ba 2 weeks ago 315MB <none> <none> d8e4b0afd6ba 2 weeks ago 551MB上面的命令会产生一个类似于下面的文本文件REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 293e4ed402ba 2 weeks ago 315MB <none> <none> d8e4b0afd6ba 2 weeks ago 551MB

  3. Make necessary edits to set the tag by using docker image tag command使用docker image tag命令进行必要的编辑以设置docker image tag

docker image tag 293e4ed402ba postgres:latest docker image tag d8e4b0afd6ba wordpress:latest

I wrote a one-line script that importing a bunch of .tar files and immediately tagging the image.我编写了一个单行脚本,用于导入一堆 .tar 文件并立即标记图像。

for image in $(ls); do docker tag "$(echo $(docker import  $image))" $image ; done

Note, that you should be inside the folder when all the tar files are located.请注意,找到所有 tar 文件后,您应该位于该文件夹内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM