8

我在 Ubuntu 14.04 的 Docker 容器中有一个 Ruby on Rails 应用程序。我使用 Dokku 设置了我的部署,但我不确定如何让我的 cron 作业正常工作。

目前我正在使用when gem,它允许我做一些简单的事情,比如:

every 5.minutes do
  runner 'MyModel.run_something'
end

问题是我认为每次部署使用git push dokku master它都会重置容器并将其设置回默认值,从而删除我所有的 cron 计划。

所以我想也许 cron 调度需要在容器之外并在 VM 级别。

无论我做什么,我目前都看不到任何 cron 作业正在运行。以下是我运行crontab -lssh 时发生的情况:

root@dashboard:~# crontab -l
no crontab for root

我对容器虚拟化很陌生,所以如果我跳过了其中的一个关键部分,我很抱歉,但我很困惑。

4

2 回答 2

10
于 2014-11-22T11:12:43.660 回答
1

Whenever probably isn't working because the cron daemon isn't running in your Docker/Dokku container. Docker will only run the processes it is told to, using either a CMD or RUN directive or in a script executed by one of those directives.

The Dokku guys have explicitly said that cron is not supported in Dokku, though without saying why. A quick search for cron in the Dokku, Buildstep and Dokku base image repos brings up no results, so it seems to be the case that Dokku never starts a cron service when building/running an app.

The solutions they suggest are to either set up the cron job on the host machine (as you've already figured out), use a web_based scheduling service, or try Heroku's Scheduler.

于 2014-11-22T18:22:11.807 回答