How to Run One-off Processes and Cron in Dokku


Dokku is a private PaaS like Heroku.
If we use this tool, we don’t have to worry about any limitation. It is so easy to use, I love it.

This article describes: One-off Processes and Cron in Dokku.


😼 Command to run for one-off process

You can fill the following command:
(The example is about Rake task in Rails)

$ dokku --rm-container run APP_NAME "bundle exec rake RAILS_ENV=production 'something:doing'"

🍄 Configure about cleanup

If you want to remove the container after a command has started, you can run the following command:

# keep `run` containers around
$ dokku config:set --global DOKKU_RM_CONTAINER=1

# revert the above setting and keep containers around
$ dokku config:unset --global DOKKU_RM_CONTAINER

🚌 Check your docker process

In my case, the docker process is sometimes alive after finishing the task.
So, I recommend you to check the docker process by the following command:

$ docker ps

If you want to cleanup unused Dokku, you should run the following command:

$ dokku cleanup

🐠 Configuration of Cron

In the official document, place your cronfiles in a pattern such as /etc/cron.d/APP.
I agree with the idea. In addition, I recommend you to manage the cron file in git(or some other version management tool).

The following text is an example of the cron file:
(Please don’t write comment and erase the last EOL in the following file.)

0 0 * * * dokku dokku --rm run APP_NAME "bundle exec rake RAILS_ENV=production 'something:doing'" >>/var/log/cron.log 2>>/var/log/cron_error.log

After you have committed the upper text to git and finished deploying it to dokku server, please run the following command:

dokku enter APP_NAME web cat config/cron.d/APP_NAME > /etc/cron.d/APP_NAME

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!