Why doesn't the cron service in Dockerfile run?

Having started crond with supervisor, your cron jobs should be executed. Here are the troubleshooting steps you can take to make sure cron is running

  1. Is the cron daemon running in the container? Login to the container and run ps a | grep cron to find out. Use docker exec -ti CONTAINERID /bin/bash to login to the container.

  2. Is supervisord running?

  3. In my setup for instance, the following supervisor configuration works without a problem. The image is ubuntu:14.04. I have CMD ["/usr/bin/supervisord"] in the Dockerfile.
[supervisord]
 nodaemon=true
[program:crond]
 command = /usr/sbin/cron
 user = root
 autostart = true
  1. Try another simple cron job to findout whether the problem is your cron entry or the cron daemon. Add this when logged in to the container with crontab -e :

    * * * * * echo "hi there" >> /tmp/test

  2. Check the container logs for any further information on cron:

    docker logs CONTAINERID | grep -i cron

These are just a few troubleshooting tips you can follow.


Cron is not running because only the last CMD overrides the first one (as @xuhdev said). It's documented here : https://docs.docker.com/reference/builder/#cmd.

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.

If you want to have nginx and cron running in the same container, you will need to use some kind of supervisor (like supervisord or others) that will be the pid 1 process of your container and manage the chield processes. I think this project should help : https://github.com/nbraquart/docker-nginx-php5-cron (it seems to do what you're trying to achieve).

Depending on what you're cron is here for, there would be other solution to that — like building a new image for each commit or each tags, etc...