docker - 调试Dockerfile

dockerfile编写的过程中,不可避免会遇到运行构建新镜像错误的问题,那么我们应该怎样调试dockerfile呢。其实,当我们遇到某个指令失败时,我们也能够得到前一个指令构建的镜像。因此,我们可以进入到前一个临时镜像,调试下一个指令。

在/root/debug-dockerfile目录下创建一个Dockerfile构建一个包含有错误命令的新镜像

root@localhost debug-dockerfile]# pwd
/root/debug-dockerfile

Dockerfile

FROM centos:7.4.1708
RUN touch tmpfile
RUN cp tmpfile tmpdir/

    很明显,该dockerfile的第三个命令是会运行失败的,因为当前目录没有tmpdir目录。

    运行Dockerfile后,报错信息如下,在step3,即 RUN cp tmpfile tmpdir/ 时出现了错误。

[root@localhost debug-dockerfile]# docker build -t debug-dockerfile .
Sending build context to Docker daemon   2.56kB
Step 1/3 : FROM centos:7.4.1708
 ---> 295a0b2bd8ea
Step 2/3 : RUN touch tmpfile
 ---> Running in 7530981ccd45
Removing intermediate container 7530981ccd45
 ---> 8408a48380c2
Step 3/3 : RUN cp tmpfile tmpdir/
 ---> Running in a50d0a45ce94
cp: cannot create regular file 'tmpdir/': Not a directory
The command '/bin/sh -c cp tmpfile tmpdir/' returned a non-zero code: 1

这时,我们可以进入到前面一个指令中获取到的临时镜像8408a48380c2,调试下一个指令。

[root@localhost debug-dockerfile]# docker run -it 8408a48380c2

通过ll命令,我们可以看到上一个命令创建的文件tmpfile

 

转载于:https://my.oschina.net/thinwonton/blog/2875227

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值