gpt4 book ai didi

cron - docker root crontab 作业未执行

转载 作者:行者123 更新时间:2023-12-01 00:36:13 25 4
gpt4 key购买 nike

我有一个 Ubuntu 14.04 docker 镜像,我想在其中安排一个 python 脚本每分钟执行一次。我的 DockerFile 包含 CMD ["cron","-f"] 以启动 cron 守护程序。 crontab 条目如下所示:

0,1 * * * * root python /opt/com.org.project/main.py >> /opt/com.org.project/var/log/cron.log

/opt/com.org.project/main.py 完全由 root 访问和拥有,并具有 744 权限集;所以可以执行。

我的 /opt/com.org.project/var/log/cron.log 文件和 /var/log/cron.log 中没有显示任何内容.然而 ps aux | grep cron 显示 cron -fPID 1 处运行。

我错过了什么?为什么我的 cron 作业没有在容器中运行?

这是我要求的 DockerFile 内容:

FROM ubuntu

# Update the os and install the dependencies needed for the container
RUN apt-get update \
&& apt-get install -y \
nano \
python \
python-setuptools \
python-dev \
xvfb \
firefox

# Install PIP for python package management
RUN easy_install pip

CMD ["cron", "-f"]

最佳答案

为什么要使用 cron?只需像这样编写一个 shell 脚本:

#!/bin/bash
while true; do
python /opt/com.org.project/main.py >> /opt/com.org.project/var/log/cron.log
sleep 60
done

然后将其设置为入口点。

ENTRYPOINT ["/bin/bash", "/loop_main.sh" ]

关于cron - docker root crontab 作业未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32465479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com