/etc/rc*未在Docker中的Ubuntu 18.04上运行。无法在启动时启动cron
我似乎无法说服/etc/rc*未在Docker中的Ubuntu 18.04上运行。无法在启动时启动cron,docker,ubuntu,init.d,Docker,Ubuntu,Init.d,我似乎无法说服cron(或任何其他)服务从我的Ubuntu容器开始。我肯定我错过了一些简单的东西 我尝试过使用更新rc.d和/etc/rc.local但没有乐趣 在本例中,Dockerfile我还试图运行rsyslog,以便进行调试,结果是相同的——服务不会启动 # syntax = docker/dockerfile:experimental FROM ubuntu:18.04 RUN apt-get update && apt-get install --reinsta
cron
(或任何其他)服务从我的Ubuntu容器开始。我肯定我错过了一些简单的东西
我尝试过使用更新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的入口点所取代 有关更多信息,请参阅: 因此,正确的解决方案是我认为是一个黑客。在my
entrypoint.sh
中,我有:
service rsyslog start
service cron start
谢谢-我学到了一些东西,但仍然坚持。ubuntu:18.04的基本图像看起来已经很精简了。没有
/sbin/init
,实际上也没有/lib/systemd/systemd
,只有一个/lib/systemd/system
目录,其中没有明显的可执行文件,但至少包含rsyslog
和cron
的文件。通过将谜题改为“为什么/sbin/init
不存在?”这就找到了解决方案(请参阅接受的答案)。非常感谢。Docker容器通常不会运行init系统或/etc/init.d
脚本;运行服务
命令可能会以多种方式失败。容器通常会将一个进程作为前台进程运行,而绝对不会运行其他进程;该进程通常不是交互式shell。