Dockerfile-在一个RUN命令中删除文件,但在下一个RUN命令中仍然存在 [英] Dockerfile - removing a file in one RUN command, it is still present in the next RUN command

查看:1982
本文介绍了Dockerfile-在一个RUN命令中删除文件,但在下一个RUN命令中仍然存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Dockerfile( https://gist.github.com/hasMobi/e198555704ee57e84399 ),依次执行以下两个命令:

I have a Dockerfile (https://gist.github.com/hasMobi/e198555704ee57e84399) that have these two commands in sequence:

RUN rm -frv /usr/share/nginx/html/*
RUN ls /usr/share/nginx/html/

在构建hte时查看控制台图像,我可以清楚地看到从该文件夹中删除了2个文件,但是当下一个RUN命令出现时,它列出了目录的内容并且文件仍然存在?:

When I look at the console while building hte image, I can clearly see 2 files being removed from that folder, but when the next RUN command comes, it lists the directory's contents and the files are still there?:

Step 6 : RUN rm -fry /usr/share/nginx/html/* 
 ---> Running in b9a69992e4e0 
removed '/usr/share/nginx/html/index.html' 
removed '/usr/share/nginx/html/index.php' 
 ---> 2bfe01cbd007 
Removing intermediate container b9a69992e4e0 
Step 7 : RUN is /usr/share/nginx/html/ 
 ---> Running in 08396f6029e1 
index.html 
index.php 
 ---> a6471052519d 

这是怎么回事?我知道每个RUN命令都会创建一个单独的层,并且一个层与另一个层是隔离的,但是第二个RUN命令不是应该以与上一个RUN命令相同的状态继承文件系统(两个文件都消失了) )?

What is going on here? I understand that each RUN command creates a separate layer and one is isolated from the other, but isn't the second RUN command supposed to inherit the file system in the exact state that it was in the previous RUN command (with the 2 files gone)?

推荐答案

我遇到了类似的问题:

   RUN rm -rf /full/path
   RUN ln -s /other /full/path

此操作失败,因为第二个RUN上仍然存在 / full / path。此解决方法有效:

This fails because "/full/path" still exists on the second RUN. This workaround works:

   RUN rm -rf /full/path; ln -s /other /full/path

我不了解行为,但能够正常工作就我而言。

I don't understand the behavior but was able to work around it in my case.

这篇关于Dockerfile-在一个RUN命令中删除文件,但在下一个RUN命令中仍然存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆