docker映象之除錯dockerfile
阿新 • • 發佈:2020-11-16
1、dockerfile構建映象的過程是怎樣的?
1、從 base 映象執行一個容器。
2、執行一條指令,對容器做修改。
3、執行類似 docker commit 的操作,生成一個新的映象層。
4、Docker 再基於剛剛提交的映象執行一個新容器。
5、重複 2-4 步,直到 Dockerfile 中的所有指令執行完畢。
2、dockerfile的除錯思路和除錯的過程是怎樣的?
如果 Dockerfile 由於某種原因執行到某個指令失敗了,我們也將能夠得到前一個指令成功執行構建出的映象,這對除錯 Dockerfile 非常有幫助。我們可以執行最新的這個映象定位指令失敗的原因。
root@richardo-docker01:~# cat Dockerfile FROM busybox RUN touch tmpfile RUN /bin/bash -c echo "continue to build ..." COPY testfile / root@richardo-docker01:~# docker build -t image-debug . Sending build context to Docker daemon 15.87kB Step 1/4 : FROM busybox latest: Pulling from library/busybox 9758c28807f2: Pull complete Digest: sha256:a9286defaba7b3a519d585ba0e37d0b2cbee74ebfe590960b0b1d6a5e97d1e1d Status: Downloaded newer image for busybox:latest ---> f0b02e9d092d Step 2/4 : RUN touch tmpfile ---> Running in 469d1dde33b3 Removing intermediate container 469d1dde33b3 ---> aa9a6f2c7f13 Step 3/4 : RUN /bin/bash -c echo "continue to build ..." ---> Running in feb6c159c54e /bin/sh: /bin/bash: not found The command '/bin/sh -c /bin/bash -c echo "continue to build ..."' returned a non-zero code: 127 root@richardo-docker01:~# docker run -it feb6c159c54e Unable to find image 'feb6c159c54e:latest' locally ^C root@richardo-docker01:~# docker run -it aa9a6f2c7f13 / # /bin/bash -c echo "continue to build ..." sh: /bin/bash: not found / # root@richardo-docker01:~#