簡體   English   中英

Docker 保存/加載丟失原始圖像存儲庫/名稱/標簽

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

我正在使用 Docker 1.12.6。

我從 Docker 注冊表中提取了一個圖像。 我已使用docker save命令將圖像導出為 tar 文件。

我刪除了原始圖像和容器,並使用docker load -i myImage.tar加載了導出的圖像。

現在,當運行docker images我注意到我的鏡像丟失了它的存儲庫/標簽信息:

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

為什么它有這種行為,我如何保留原始圖像名稱?

采用

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

命令docker save <image id>刪除存儲庫和標簽名稱。

要解決此問題,請使用docker save <repo>:<tag>它將存儲庫和標簽名稱保留在保存的文件中。 例如:

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

我遇到了同樣的問題,所以我使用以下命令手動修復它:

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

參考


[注意]:

不一致: 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 repo

將所有標記的圖像 + 父項保存在存儲庫中,並創建一個列出標記的存儲庫文件

docker save repo:tag

將標記的圖像 + 父項保存在 repo 中,並創建一個列出標記的存儲庫文件

docker save imageid

保存圖像 + 父項,不創建存儲庫文件。 保存僅與圖像相關,標簽被設計遺漏,留作練習,供用戶根據自己的命名約定填充。

參考

單個圖像 ID可以有多個名稱/標簽,因此您丟失名稱和標簽的方式是我希望在將圖像保存到 tar 球或從 tar 球加載圖像后會發生的情況。

模式的細節是關於它的討論在這里

來自 docker 文檔:

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

這個對我有用。

這是一個解決方法

  1. 轉到源 docker 主機,使用以下命令docker image ls > images.txt創建包含所有圖像詳細信息的文本文件

  2. 上面的命令會產生一個類似於下面的文本文件REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 293e4ed402ba 2 weeks ago 315MB <none> <none> d8e4b0afd6ba 2 weeks ago 551MB

  3. 使用docker image tag命令進行必要的編輯以設置docker image tag

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

我編寫了一個單行腳本,用於導入一堆 .tar 文件並立即標記圖像。

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

請注意,找到所有 tar 文件后,您應該位於該文件夾內。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM