sad*_*ave 3 cron docker ubuntu-14.04 dockerfile
我有一个Ubuntu 14.04docker 映像,我想在其中安排一个 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
Run Code Online (Sandbox Code Playgroud)
/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 -f正在运行PID 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"]
Run Code Online (Sandbox Code Playgroud)
小智 6
为什么要使用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
Run Code Online (Sandbox Code Playgroud)
然后将其设置为入口点。
ENTRYPOINT ["/bin/bash", "/loop_main.sh" ]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4600 次 |
| 最近记录: |