Docker容器中的Cronjobs如何使其运行? [英] Cronjobs in Docker container how get them running?

查看:134
本文介绍了Docker容器中的Cronjobs如何使其运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的debian docker容器中有一些cronjobs。他们为什么不自动启动?

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

我必须采取一些解决方法吗?

Do I have to do some workarounds?

推荐答案

如果您在docker中运行容器,则可以在docker主机上添加cron任务以在docker容器中执行命令。

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

例如,要每5分钟在容器中运行一次压力应用程序,可以将以下内容(当然替换为容器ID)添加到crontab中:

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

我在docker上以root用户身份运行

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

或只需运行cron:

root@dockerhost:cron

这篇关于Docker容器中的Cronjobs如何使其运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆