bash Docker:Cronjob 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24943982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Docker: Cronjob is not working
提问by rgaut
I am trying to run cron job on Docker container. I have a running container (Fedora 20). I have also installed cron packages in container and explicitly run the cron daemon. I have also checked cron.deny file it is empty and there is no file called cron.allow under /etc/ directory.
我正在尝试在 Docker 容器上运行 cron 作业。我有一个正在运行的容器(Fedora 20)。我还在容器中安装了 cron 包并显式运行 cron 守护进程。我还检查了 cron.deny 文件,它是空的,并且 /etc/ 目录下没有名为 cron.allow 的文件。
Whenever I tried to set the cronjob by using crontab -e or trying to list the cron job using
crontab -l I am getting following error.
bash-4.2# crontab -l
You (root) are not allowed to access to (crontab) because of pam configuration.
bash-4.2# crontab -e
You (root) are not allowed to access to (crontab) because of pam configuration.
I also checked the /etc/pam.d/crond file it has following entry
我还检查了 /etc/pam.d/crond 文件,它具有以下条目
bash-4.2# vi /etc/pam.d/crond
bash-4.2# vi /etc/pam.d/crond
#
# The PAM configuration file for the cron daemon
#
#
# No PAM authentication called, auth modules not needed
account required pam_access.so
account include password-auth
session required pam_loginuid.so
session include password-auth
auth include password-auth
Has any one faced this issue? If yes could you please suggest me some pointer on this?
有没有人遇到过这个问题?如果是的话,你能给我建议一些关于这个的指针吗?
thanks in advance.
提前致谢。
回答by Mark O'Connor
An LXC container is not a virtual machine. You'll need to explictly run the cron daemon in the foreground. Better still run cron from program like Supervisoror runit.
LXC 容器不是虚拟机。您需要在前台显式运行 cron 守护程序。最好还是从像Supervisor或runit这样的程序运行 cron 。
Reference: Docker documentation
参考:Docker 文档
Traditionally a Docker container runs a single process when it is launched, for example an Apache daemon or a SSH server daemon. Often though you want to run more than one process in a container. There are a number of ways you can achieve this ranging from using a simple Bash script as the value of your container's CMD instruction to installing a process management tool.
In this example we're going to make use of the process management tool, Supervisor, to manage multiple processes in our container. Using Supervisor allows us to better control, manage, and restart the processes we want to run. To demonstrate this we're going to install and manage both an SSH daemon and an Apache daemon.
传统上,Docker 容器在启动时运行单个进程,例如 Apache 守护进程或 SSH 服务器守护进程。尽管您通常希望在一个容器中运行多个进程。有多种方法可以实现这一点,从使用简单的 Bash 脚本作为容器 CMD 指令的值到安装进程管理工具。
在此示例中,我们将使用进程管理工具 Supervisor 来管理容器中的多个进程。使用 Supervisor 可以让我们更好地控制、管理和重启我们想要运行的进程。为了演示这一点,我们将安装和管理 SSH 守护程序和 Apache 守护程序。
回答by Col Wilson
You can do:
你可以做:
ENTRYPOINT cron -f
入口点 cron -f
although remember that you can only have one ENTRYPOINT.
但请记住,您只能有一个入口点。
From the docs:
从文档:
There can only be one ENTRYPOINT in a Dockerfile. If you have more than one ENTRYPOINT, then only the last one in the Dockerfile will have an effect.
An ENTRYPOINT helps you to configure a container that you can run as an executable. That is, when you specify an ENTRYPOINT, then the whole container runs as if it was just that executable.
一个 Dockerfile 中只能有一个 ENTRYPOINT。如果您有多个 ENTRYPOINT,则只有 Dockerfile 中的最后一个会起作用。
ENTRYPOINT 可帮助您配置可以作为可执行文件运行的容器。也就是说,当您指定一个 ENTRYPOINT 时,整个容器就好像它只是那个可执行文件一样运行。