簡體   English   中英

/etc/rc* 未在 Docker 中的 Ubuntu 18.04 上運行。 啟動時無法啟動 cron

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

我似乎無法說服cron (或任何其他)服務從我的 Ubuntu 容器開始。 我確定我錯過了一些簡單的東西。

我試過同時使用update-rc.d/etc/rc.local但沒有任何樂趣。

在此示例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"]

當我運行容器時:

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

將 CMD 添加到您的 Dockerfile:

CMD ["/sbin/init"]

作為init,程序負責系統初始化。 在此處閱讀有關 init 的更多信息

根據設計,systemd 不在 ubuntu docker 映像中

這是因為它作為 PID 1 的角色被 docker 的入口點有效地取代了

有關更多信息,請參閱:

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

所以正確的解決方案是我認為的黑客。 在我的entrypoint.sh中,我有:

service rsyslog start
service cron start

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM