2015-09-19 46 views
2

大家好我只是有dockerized除了我的cron作業我的整個應用程序,這裏是我dockerFile泊塢窗的Node.js的Cron

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並手動添加它,它可以正常工作。

任何想法我做錯了什麼?

感謝

+1

你在/var/log/cron.log中看到有什麼可疑的東西嗎? –

+0

其空。還有什麼我應該看看? – MrB

回答

1

在你缺少用戶名格式

你的cron文件的第二行,以便代替

* * * * * cd /var/sites/services/ldapSync && node index.js >> 2>&1 

你應該有

* * * * * root cd /var/sites/services/ldapSync && node index.js >> 2>&1 

欲瞭解更多信息見this

0

看一看redmatter/cron圖片。我花了一段時間纔得到crond的表現。

在github上的test子文件夾中有一個示例。您也可以參考我的answer here