How to solve “invoke-rc.d: policy-rc.d denied execution of start.” when building a container Ubuntu

本文介绍了解决在使用Dockerfile构建基于Ubuntu的Apache服务器时遇到的错误“invoke-rc.d: policy-rc.d denied execution of start”的方法。提供了一种简单解决方案:在Dockerfile中加入特定命令行以禁用policy-rc.d限制,以及讨论了使用特权模式运行容器的风险。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题场景:通过Dockerfile构建基于ubuntu的apache服务器时报错

invoke-rc.d: policy-rc.d denied execution of start.

在stackoverflow站点上看到一个问题回答,借鉴后解决了我的问题,答案如下

Here is a good post which tries to root cause the issue you are facing.

Shorter way:

    RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d should resolve your issue OR

    If that doesn't resolve the issue, try running your docker container with privileged option. Like this, docker run --privileged -d -ti DOCKER_IMAGE:TAG

Ideally, I would not recommend running container with privileged option unless its a test bed container. The reason being running a docker container with privileged gives all capabilities to the container, and it also lifts all the limitations enforced. In other words, the container can then do almost everything that the host can do. But this is not a good practice. This defeats the docker purpose of isolating from host machine.

The ideal way to do this is to set capabilities of your docker container based on what you want to achieve. Googling this should help you out to provide appropriate capability for your docker container

在Dockerfile中加上

RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d

重新构建后就没有报这个错误了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值