简体   繁体   English

为什么“ RUN rm /etc/nginx/conf.d/default.conf”没有成功?

[英]Why “RUN rm /etc/nginx/conf.d/default.conf” did not succeed?

I don't want my nginx docker image to have /etc/nginx/conf.d/default.conf so I wrote a simple nginx dockerfile, mainly to add RUN rm /etc/nginx/conf.d/default.conf 我不希望我的nginx /etc/nginx/conf.d/default.conf映像具有/etc/nginx/conf.d/default.conf所以我编写了一个简单的nginx dockerfile,主要是添加RUN rm /etc/nginx/conf.d/default.conf

To my surprise it did not work. 令我惊讶的是,它没有用。 /etc/nginx/conf.d/default.conf is still there. /etc/nginx/conf.d/default.conf仍然存在。

Why and how do I delete it ? 为什么以及如何删除它?

My dockerfile: 我的dockerfile:

FROM nginx:latest

# Copy custom configuration file from the current directory
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/nginx.conf
COPY conf.d/node2 /etc/nginx/conf.d/node2
EXPOSE 80 8080

My docker-compose.yml for nginx service adds a name volumn 我的nginx服务的docker-compose.yml添加了一个名字volumn

volumes:
- conf:/etc/nginx/conf.d

Update: 更新:

I finally found out that it is because I created a name volume in my docker-compose.yml that create /etc/nginx/conf.d/default.conf so rm in dockerfile won't work at all. 我终于发现这是因为我在docker-compose.yml中创建了一个名称卷,该名称卷创建了/etc/nginx/conf.d/default.conf因此/etc/nginx/conf.d/default.conf rm根本无法工作。 But why creating a name volume will result in creating `/etc/nginx/conf.d/default.conf ? 但是为什么创建名称卷会导致创建`/etc/nginx/conf.d/default.conf?

Update2: 更新2:

With the second answer I got I finally figure out why. 有了第二个答案,我终于明白了为什么。 So RUN rm /etc/nginx/conf.d/default.conf did work. 所以RUN rm /etc/nginx/conf.d/default.conf确实起作用了。 The problem is I used a volume in my docker-compose.yml that was created before I run RUN rm /etc/nginx/conf.d/default.conf and that volume has default.conf. 问题是我在docker-compose.yml中使用了一个在运行RUN rm /etc/nginx/conf.d/default.conf之前创建的卷,并且该卷具有default.conf。

It happened like this, I first used a dockerfile without rm and run docker-compose up , then I added rm to it to rebuild the image and run docker-compose up again. 这样的事情发生了,我首先使用了一个不带rm的dockerfile并运行docker docker-compose up ,然后我向其中添加了rm来重建映像并再次运行docker-compose up But I never change my docker-compose.yml or clean my volume. 但是我永远不会更改docker-compose.yml或清理卷。 So the file was there no matter how I build/rebuild my image. 因此,无论我如何构建/重建映像,文件都在那里。

After I deleted all the old volume (using docker volume rm docker volume ls -q -f dangling=true ) it finally works. 在删除所有旧卷(使用docker volume rm docker volume ls -q -f dangling=true )后,它终于可以工作了。

I leave my question here instead of deleting it just in case someone else may make the same mistake like I did :$ 我在这里留下我的问题,而不是删除它,以防万一有人可能会像我一样犯同样的错误:$

I don't think you're using your new image. 我认为您使用的不是新图片。

I tested it by simply creating a new Dockerfile: 我通过简单地创建一个新的Dockerfile进行了测试:

FROM nginx:alpine

RUN rm /etc/nginx/conf.d/default.conf

and I've executed the following commands: 并且我执行了以下命令:

docker build -t test-nginx .
docker run -it --name mynginx-instance test-nginx ls -la /etc/nginx/conf.d
docker rm mynginx-instance

Volumes are a run time change to the filesystem. 卷是对文件系统的运行时更改。 The build runs without your volume to create the image. 运行该构建时无需创建卷即可创建映像。 Therefore the file is deleted in the image, but then you mount a volume in your container that has the file. 因此,该文件在映像中被删除,但是随后您在具有该文件的容器中装入了一个卷。

The fix is to either not use a volume so you can see the filesystem as it exists in the image, or you can delete the file from the volume. 解决方法是不使用卷,以便您可以看到映像中存在的文件系统,或者可以从卷中删除文件。 The following should work for cleaning the file from the volume: 以下应该可以从卷中清除文件:

docker run -it --rm -v ${vol_name}:/target busybox rm /target/default.conf

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法启动 nginx-proxy docker 映像并显示错误“/etc/nginx/conf.d/default.conf 的内容未更改” - Couldn't start nginx-proxy docker image with error “Contents of /etc/nginx/conf.d/default.conf did not change” nginx:[emerg] 在 /etc/nginx/conf.d/default.conf 的上游“api:5000”中找不到主机 - nginx: [emerg] host not found in upstream "api:5000" in /etc/nginx/conf.d/default.conf 使用 docker 和 nginx 部署的 React 应用程序:/etc/nginx/conf.d/default.conf 与包不同 - React app deployed with docker and nginx : /etc/nginx/conf.d/default.conf differs from the packages nginx: [emerg] "http" 指令在 /etc/nginx/conf.d/default.conf:1 中是不允许的 - nginx: [emerg] "http" directive is not allowed here in /etc/nginx/conf.d/default.conf:1 1#1: pread() “/etc/nginx/conf.d/default.conf” 失败(38: Function 未实现) - 1#1: pread() “/etc/nginx/conf.d/default.conf” failed (38: Function not implemented) /etc/nginx/conf.d/default.conf:1 中的上游“9000”中没有端口 - no port in upstream “9000” in /etc/nginx/conf.d/default.conf:1 无法在 nginx /etc/nginx/conf.d/default.conf 中复制配置文件 - Unable to COPY config file in nginix /etc/nginx/conf.d/default.conf AWS ECR,基于 ECS 的部署:nginx:[emerg] 主机未在上游“app:9000”中找到,位于 /etc/nginx/conf.d/default.conf:2 - AWS ECR, ECS based deployment: nginx: [emerg] host not found in upstream "app:9000" in /etc/nginx/conf.d/default.conf:2 Docker 撰写错误:nginx:在 /etc/nginx/conf.d/default.conf:21 的上游“应用程序”中找不到 [emerg] 主机 - Docker compose error: nginx: [emerg] host not found in upstream “app” in /etc/nginx/conf.d/default.conf:21 ERPNEXT - docker frappe/erpnext-nginx:v14 - 在 /etc/nginx/conf.d/default.conf:2 的上游“${BACKEND}”中找不到主机 - ERPNEXT - docker frappe/erpnext-nginx:v14 - host not found in upstream "${BACKEND}" in /etc/nginx/conf.d/default.conf:2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM