Docker: Cronjob is not working

后端 未结 2 897
小蘑菇
小蘑菇 2020-12-21 10:59

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

相关标签:
2条回答
  • 2020-12-21 11:16

    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 Supervisor or runit.

    Reference: Docker documentation

    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.

    0 讨论(0)
  • 2020-12-21 11:18

    You can do:

    ENTRYPOINT 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.

    0 讨论(0)
提交回复
热议问题