Cronjobs in Docker container how get them running?

佐手、 提交于 2019-12-12 09:19:05

问题


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

Do I have to do some workarounds?


回答1:


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



回答2:


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

cron

Then jobs will start regularly.




回答3:


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.




回答4:


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.

!/bin/bash

/etc/init.d/cron start



来源:https://stackoverflow.com/questions/31654125/cronjobs-in-docker-container-how-get-them-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!