Cronjobs in Docker container how get them running?

I've got some cronjobs in my debian docker container. They don't start automatically why?

Do I have to do some workarounds?


If you are running containers in docker, you can add cron tasks on the docker host machine to execute commands in the docker containers.

For example, to run 'stress' application in your container every 5 minutes you can add the following (substituting your container ID of course) to your crontab:

*/5 * * * * docker exec c78ddbed4ad9 /bin/sh -c 'stress -d 1 --hdd-bytes 64M --cpu 1 --io 2 --vm 2 --vm-bytes 64M --timeout 60s' >> /tmp/cronstress.log 2>&1

I am running this as root user on the docker host.

or just run cron:


Run cron daemon in docker container first. When login to container, in shell run follow command:


Then jobs will start regularly.

Where did you start cron? In a Dockerfile? There doing it within a RUN won't work because that process will not keep running. You need to do that e.g. via CMD. A better idea would be using a suzpervisord.

cronjob is not starting the logrotation in docker container. my cronjob looks as below:

30 9 * * * root /usr/sbin/logrotate /etc/logrotate.d/apache2

Also I have added below script as ENTRYPOINT in docker file to start cron.


/etc/init.d/cron start

Need Your Help

Restrict deployment to certain environments based on version tag

deployment tfs versioning octopus-deploy

I'm finalising my CI setup with TFS and I have one last part to overcome. Currently, every CI build is pushed to octopus with the nuget packages versioned as major.minor.patch.buildid, and these ar...