第 3 章 镜像 - 015 - 调试 Dockerfile
生活随笔
收集整理的這篇文章主要介紹了
第 3 章 镜像 - 015 - 调试 Dockerfile
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
如何 debug Dockerfile
通過 Dockerfile 構建鏡像的過程
如果 Dockerfile 由于某種原因執行到某個指令失敗了,我們也將能夠得到前一個指令成功執行構建出的鏡像,可以運行最新的這個鏡像定位指令失敗的原因。
舉個例子
Dockerfile
1 FROM busybox 2 RUN touch tmpfile 3 RUN /bin/bash -c echo "continue to build ....." 4 COPY testfile /?
?構建過程如下
1 root@ubuntu:~# cat Dockerfile 2 FROM busybox 3 RUN touch tmpfile 4 RUN /bin/bash -c echo "continue to build ....." 5 COPY testfile / 6 root@ubuntu:~# 7 root@ubuntu:~# docker build -t image-debug . 8 Sending build context to Docker daemon 23.04kB 9 Step 1/4 : FROM busybox 10 latest: Pulling from library/busybox 11 57c14dd66db0: Pull complete 12 Digest: sha256:b6e640a3768c460ad6066a003b6da52034c31aaf8500f9263057ddffcd830ef6 13 Status: Downloaded newer image for busybox:latest 14 ---> 3a093384ac30 15 Step 2/4 : RUN touch tmpfile 16 ---> Running in 3ba6dbde130c 17 Removing intermediate container 3ba6dbde130c 18 ---> 3043ba551c41 19 Step 3/4 : RUN /bin/bash -c echo "continue to build ....." 20 ---> Running in a16303c0b2f7 21 /bin/sh: /bin/bash: not found 22 The command '/bin/sh -c /bin/bash -c echo "continue to build ....."' returned a non-zero code: 127?21行出現錯誤,可以使用?3043ba551c41?進行調試。
1 root@ubuntu:~# docker run -it 3043ba551c41 2 / # /bin/bash -c echo "continue to build ....." 3 sh: /bin/bash: not found 4 / #手工執行 RUN 指令很容易定位失敗的原因是 busybox 鏡像中沒有 bash。
?
------------引用來自------------
https://mp.weixin.qq.com/s?__biz=MzIwMTM5MjUwMg==&mid=2653587606&idx=1&sn=656e82adf088ae2652d245dc49b94873&chksm=8d30808fba470999569781cb1f8db769126769717f8899993cab6e4c36c65da0ed4a3205cf99&scene=21#wechat_redirect
轉載于:https://www.cnblogs.com/gsophy/p/10221885.html
總結
以上是生活随笔為你收集整理的第 3 章 镜像 - 015 - 调试 Dockerfile的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 需求分析——掌握和使用UML建模语言顺序
- 下一篇: 非对称加密, 助记词, PIN, WIF