语境
我正在尝试 日程安排 中的一些摄取工作 Alpine 容器。我花了一段时间才明白为什么我的 定时任务 没有启动:crond 似乎没有运行
rc-service -l | grep crond
根据 Alpine's documentation , crond 必须首先以 openrc
开始(即某种 systemctl
)。这是 DockerfileFROM python:3.7-alpine
# set work directory
WORKDIR /usr/src/collector
RUN apk update \
&& apk add curl openrc
# ======>>>> HERE !!!!!
RUN rc-service crond start && rc-update add crond
# install dependencies
RUN pip install --upgrade pip
RUN pip install pipenv
COPY ./Pipfile /usr/src/collector/Pipfile
RUN pipenv install --skip-lock --system --dev
# copy entrypoint.sh
COPY ./entrypoint.sh /usr/src/collector/entrypoint.sh
# copy project
COPY . /usr/src/collector/
# run entrypoint.sh
ENTRYPOINT ["/usr/src/collector/entrypoint.sh"]
entrypoint.sh
仅在 /etc/crontabs/root
的末尾附加作业问题
我收到以下错误:
* rc-service: service `crond' does not exist
ERROR: Service 'collector' failed to build: The command '/bin/sh -c rc-service crond start && rc-update add crond' returned a non-zero code: 1
事情开始变得有点循环。 rc-service 如何同时不识别服务:sh
好像知道名字crond
,/etc/crontabs/root
我错过了什么?
最佳答案
一些 Alpine Docker 容器缺少 busybox-initscripts package .只需将其附加到您的 apk add
的末尾命令,并且 crond 应该作为服务运行。
您可能还需要从 Dockerfile 中删除以下行,因为它似乎是 busybox-initscripts 安装后立即将 crond 作为服务运行:
RUN rc-service crond start && rc-update add crond
关于docker - 在 Alpine 容器中启用 crond,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56901751/