【问题标题】:Docker Node.js CronDocker Node.js Cron
【发布时间】:2015-12-16 05:48:42
【问题描述】:

大家好,我只是将我的整个应用程序 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 world,它就可以正常工作,但是当我在那里有节点 cron 时,它似乎没有做任何事情。如果我进入容器并执行 crontab -e 并手动添加它就可以了。

任何想法我做错了什么?

谢谢

【问题讨论】:

  • 你在 /var/log/cron.log 中看到了什么可疑的东西吗?
  • 它是空的。还有什么我应该看的吗?

标签: node.js cron docker


【解决方案1】:

在您的 cron 文件的第二行中,您缺少格式中的用户名

所以不是

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

你应该有

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

欲了解更多信息,请参阅this

【讨论】:

    【解决方案2】:

    看看redmatter/cron 图像。我花了一段时间才让crond 表现良好。

    github的test子文件夹中有一个例子。

    也可以参考我的answer here。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-18
      • 2016-12-31
      • 1970-01-01
      • 2015-08-12
      • 2016-01-18
      • 2015-08-15
      • 2017-04-01
      • 2022-09-23
      相关资源
      最近更新 更多