简体   繁体   English

/etc/rc* 未在 Docker 中的 Ubuntu 18.04 上运行。 启动时无法启动 cron

[英]/etc/rc* not running on Ubuntu 18.04 in Docker. Cannot start cron on boot

I can't seem to convince the cron (or any other) service to start with my Ubuntu container.我似乎无法说服cron (或任何其他)服务从我的 Ubuntu 容器开始。 I'm sure I'm missing something simple.我确定我错过了一些简单的东西。

I've tried using both update-rc.d and /etc/rc.local but no joy.我试过同时使用update-rc.d/etc/rc.local但没有任何乐趣。

In this example Dockerfile I'm also trying to get rsyslog running in order to debug, with the same result- the service does not start.在此示例Dockerfile ,我还尝试运行rsyslog以进行调试,结果相同 - 服务未启动。

# syntax = docker/dockerfile:experimental

FROM ubuntu:18.04


RUN apt-get update && apt-get install --reinstall -y \
    rsyslog

# fix for https://stackoverflow.com/questions/56609182/openthread-environment-docker-rsyslogd-imklog-cannot-open-kernel-log-proc-km
RUN sed -i '/imklog/s/^/#/' /etc/rsyslog.conf

# run at startup
RUN update-rc.d rsyslog defaults

# ...really run at startup
RUN echo "service rsyslog start" >> /etc/rc.local

RUN apt-get update && apt-get install -y \
    cron

# run at startup
RUN update-rc.d cron defaults

# ...really run at startup
RUN echo "service cron start" >> /etc/rc.local

ENTRYPOINT ["/bin/bash"]

When I run the container:当我运行容器时:

root@e392a9404e0f:/# service --status-all
 [ - ]  cron
 [ ? ]  hwclock.sh
 [ - ]  procps
 [ - ]  rsyslog
root@e392a9404e0f:/# service cron start
 * Starting periodic command scheduler cron                                                                             [ OK ] 
root@e392a9404e0f:/# service --status-all
 [ + ]  cron
 [ ? ]  hwclock.sh
 [ - ]  procps
 [ - ]  rsyslog

Add CMD to your Dockerfile:将 CMD 添加到您的 Dockerfile:

CMD ["/sbin/init"]

As init, the program is responsible for system initialization.作为init,程序负责系统初始化。 Read more about init here 在此处阅读有关 init 的更多信息

systemd is not in the ubuntu docker images, by design根据设计,systemd 不在 ubuntu docker 映像中

This is because its role as PID 1 is effectively replaced by docker's entrypoint这是因为它作为 PID 1 的角色被 docker 的入口点有效地取代了

For more, see:有关更多信息,请参阅:

https://stackoverflow.com/a/39169889/1892116 https://stackoverflow.com/a/39169889/1892116

So the correct solution is what I thought was a hack.所以正确的解决方案是我认为的黑客。 In my entrypoint.sh I have:在我的entrypoint.sh中,我有:

service rsyslog start
service cron start

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM