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.

在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

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

猜你喜欢

转载自blog.csdn.net/sky_jiangcheng/article/details/80309176