docker镜像之调试dockerfile

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:~#
原文地址:https://www.cnblogs.com/Richardo-M-Q/p/13983660.html