Cronjobs in Docker container how get them running?
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.
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:
root@dockerhost:cron