我有一个简单的Dockerfile如下
FROM ubuntu:latest
ADD crontab /etc/cron.d/test-cron
RUN chmod a+x /etc/cron.d/test-cron
RUN touch /var/log/cron.log
CMD cron && tail -f /var/log/cron.log
Run Code Online (Sandbox Code Playgroud)
和crontab文件的内容一样简单
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
# empty line
Run Code Online (Sandbox Code Playgroud)
当我在我的本地OS X机器上运行它(运行docker-machine)时,它工作正常("Hello world"每分钟打印到日志文件).但是,当我尝试在Ubuntu机器上运行它时,cron作业不会运行(空日志文件).
这是我用来运行容器的命令
docker build -t crontest .
docker run --name cron crontest
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会这样.我想知道我的Ubuntu盒子是否有问题(错误的时间设置?).我试图重启该机器无效.我目前在Ubuntu盒子上运行其他docker容器,它们运行正常.
关于如何调试/修复此问题的任何建议都将非常受欢迎.
编辑:
进入容器(docker exec -it cron /bin/bash)后,我可以验证cron是否在那里运行:
root@a2ad451af8d9:/# ps -ef | grep cron
root 1 0 0 20:15 ? 00:00:00 /bin/sh -c cron && tail -f …Run Code Online (Sandbox Code Playgroud) 为了运行ssh守护程序服务,pam_loginuid必须在/etc/pam.d/sshd中将条目设置为可选,如Ubuntu 13.10 的官方示例中所述.
以前的Ubuntu版本是否可以选择此条目?它甚至在Ubuntu 13.10之前存在吗?
什么是设置pam_loginuid到optional的意思是,无论如何?
在这方面,我的ssh配置是不是很安全?
我试图通过Centos docker容器中的Crontab运行一些python脚本,但我没有尝试过任何工作.
首先我安装了cron:
yum install vixie-cron
Run Code Online (Sandbox Code Playgroud)
然后我把它作为服务运行:
/etc/init.d/crond start
Run Code Online (Sandbox Code Playgroud)
(我也跑了,/sbin/service crond因为对相关问题的一些答案建议如此)
ps aux | grep cron 说明:
root 16917 0.0 0.0 23288 1252 ? Ss 18:53 0:00 crond
root 16929 0.0 0.0 9720 836 pts/0 S+ 18:55 0:00 grep cron
Run Code Online (Sandbox Code Playgroud)
crontab -l 好像:
0 17 1 * * /root/proj/env/bin/python /root/proj/files/frontend/file1.py > /var/log/cron.log
0 9 4 * * /root/proj/env/bin/python /root/proj/files/frontend/file2.py > /var/log/cron.log
0 17 15 * * /root/proj/env/bin/python /root/proj/files/frontend/file3.py > /var/log/cron.log
0 9 18 * * /root/proj/env/bin/python …Run Code Online (Sandbox Code Playgroud)