Docker Node.js Cron
大家好我只是有我的整个应用程序dockerized除了我的cron作业这里是我的dockerFile
FROM nodesource/precise # Update install os dep RUN apt-get update && apt-get install -y apt-utils cron RUN apt-get -y install pwgen python-setuptools curl git unzip vim # Add code RUN mkdir /var/sites ADD /api /var/sites/api ADD /services /var/sites/services RUN cd /var/sites/services && npm install RUN cd /var/sites/api && npm install # Add crontab file in the cron directory ADD crontab /etc/cron.d/hello-cron # Give execution rights on the cron job RUN chmod 0644 /etc/cron.d/hello-cron # Create the log file to be able to run tail RUN touch /var/log/cron.log # Run the command on container startup CMD cron && tail -f /var/log/cron.log
我的cron文件
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1 * * * * * cd /var/sites/services/ldapSync && node index.js >> 2>&1 # An empty line is required at the end of this file for a valid cron file.
如果我删除节点cron作业只留下hello世界它工作正常,但是当我有节点cron在那里它似乎没有做任何事情。 如果我进入容器,并执行crontab -e并手动添加它工作正常。
任何想法我做错了什么?
谢谢
在你的cron文件的第二行中,你缺less格式的用户名
所以,而不是
* * * * * cd /var/sites/services/ldapSync && node index.js >> 2>&1
你应该有
* * * * * root cd /var/sites/services/ldapSync && node index.js >> 2>&1
欲了解更多信息,请参阅
看看redmatter/cron
图像。 我花了一段时间才得到crond
的performance。
在github上的testing子文件夹中有一个例子。
你也可以参考我的答案 。