dcoker-compose - How to execute crontab under docker
習慣沉默
習慣沉默 2017-05-24 11:32:55
0
2
1041

The project runs under docker. Now there is a requirement for crontab. I want to add crontab under docker, but I find that it cannot be added. How do the experts who use docker add their own crontab under docker?
The project uses docker-compose 2.0
The system is equipped with ubuntu
The language is php7

習慣沉默
習慣沉默

reply all(2)
刘奇

My approach:

1. Install crontab in the Dockerfile.
2. Use the volume 把本地的 etc/crontab file to map it in. Of course, you can also write it directly in the Dockerfile
3, and use supervisor to start the main application and crontab

In fact, using crontab is nothing more than: installation, configuration, and startup. The first two steps are written directly in the Dockerfile when building. The key is how to start, because Docker only accepts one CMD and cannot start the main application and crontab at the same time. Just use supervisor.

PHPzhong

1.Dockerfile is as follows

FROM centos
MAINTAINER zhaojunlike<zhaojunlike@gmail.com>
ADD ./crond/task.sh /server/task.sh
##安装并添加任务到crontab
RUN yum install crontabs -y \
    && (crontab -l; echo "*/1 * * * * /server/task.sh >>/var/log/task.log" ) | crontab
CMD crond

You can add to docker-compose to build

2. You can use other scripts to write a daemon program to simulate crontab implementation

3. Implement it on the host (not recommended)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template