[Docker] docker build 現在不會印出中間層映像檔的 ID 了?

[Docker] docker build 現在不會印出中間層映像檔的 ID 了?

今天想要從 Dockerfile 建立出 Docker 映像檔時,

因為 Ubuntu 22.04 的 APT 找不到 Azure CLI 2.29.2-1,所以失敗了:

$ docker build -t deploy-cd .

[+] Building 5.9s (22/26)
......
 => [ 1/23] FROM docker.io/library/ubuntu:22.04@sha256:2a7dffab37165e8b4f206f61cfd984f8bb279843b070217f6ad310c9c31c9c7c                   0.0s
 => CACHED [ 2/23] RUN apt-get update                                                                                                     0.0s
 => CACHED [ 3/23] RUN apt-get install -y gnupg                                                                                           0.0s
 => CACHED [ 4/23] RUN apt-get install -y curl                                                                                            0.0s
......
 => CACHED [18/23] RUN apt-get install -y terraform=0.13.3                                                                                0.0s
 => ERROR [19/23] RUN apt-get install -y azure-cli=2.29.2-1~$(lsb_release -cs)                                                            4.4s
------
 > [19/23] RUN apt-get install -y azure-cli=2.29.2-1~$(lsb_release -cs):
#22 1.417 Reading package lists...
#22 3.618 Building dependency tree...
#22 4.221 Reading state information...
#22 4.246 Package azure-cli is not available, but is referred to by another package.
#22 4.246 This may mean that the package is missing, has been obsoleted, or
#22 4.246 is only available from another source
#22 4.246
#22 4.271 E: Version '2.29.2-1~jammy' for 'azure-cli' was not found
------
executor failed running [/bin/sh -c apt-get install -y azure-cli=2.29.2-1~$(lsb_release -cs)]: exit code: 100

 

記得以前都會在執行 docker build 時,

把每一個中間層的 ID 印出來,這樣就可以進到最後一層去看看為什麼會失敗。

但現在 docker build 的輸出,完全沒有中間層的 ID 耶?

 

查了一下,原來現在得要加上  DOCKER_BUILDKIT=0 這個環境變數,

才會顯示出中間層的 ID,

同時也會把每個指令的輸出都印出來,就和以前一樣:

$ DOCKER_BUILDKIT=0 docker build -t deploy-cd .

Sending build context to Docker daemon  3.072kB
Step 1/23 : FROM ubuntu:22.04
22.04: Pulling from library/ubuntu
8527c5f86ecc: Already exists
Digest: sha256:2a7dffab37165e8b4f206f61cfd984f8bb279843b070217f6ad310c9c31c9c7c
Status: Downloaded newer image for ubuntu:22.04
 ---> 3f4714ee068a
Step 2/23 : RUN apt-get update
 ---> Running in 1f85bce584c9
Get:1 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [99.4 kB]
......
Removing intermediate container d75dd8e1ac2e
 ---> c21780201c38
Step 19/23 : RUN apt-get install -y azure-cli=2.29.2-1~$(lsb_release -cs)
 ---> Running in a3e1cdc6e0b2
Reading package lists...
Building dependency tree...
Reading state information...
Package azure-cli is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Version '2.29.2-1~jammy' for 'azure-cli' was not found
The command '/bin/sh -c apt-get install -y azure-cli=2.29.2-1~$(lsb_release -cs)' returned a non-zero code: 100

 

如上,在第 19 步時失敗了,

因此我們就可以進到第 18 步建出來的中間層 c21780201c38 去試看看:

docker run -it c21780201c38 /bin/bash

 

進到這一層之後,就可以嘗試看看,

怎樣才能將想要的 Azure CLI 版本裝上去囉~

 

參考資料:Getting docker build to show IDs of intermediate containers

(本頁面已被瀏覽過 238 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料