Docker save/load lose original image repository/na

2020-08-09 06:20发布

问题:

I'm using Docker 1.12.6.

I have pulled an image from the Docker registry. I have exported the images as tar files using the docker save command.

I removed the original image and container and loaded the exported image using docker load -i myImage.tar.

Now, when running docker images I notice my image have lost its repository/tag information:

    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?

回答1:

Use

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

The command docker save <image id> removes the repository and tag names.

To solve this, use docker save <repo>:<tag> it will keep the repository and tag name in the saved file. For example:

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


回答2:

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.

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

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



回答3:

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.

Mode details are in the discussion about it here



回答4:

From docker documentation:

cat exampleimage.tgz | docker import - 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.