Home>Article>Operation and Maintenance> How docker solve the problem that crontab does not take effect

How docker solve the problem that crontab does not take effect

WBOY
WBOY Original
2022-08-16 18:18:36 7704browse

Solution: 1. Check whether "/etc/init.d/crond status" in the container is in the running state; 2. Modify the "/etc/pam.d/crond" file and change the "required" "Change to "sufficient"; 3. Use "/etc/init.d/crond restart" to restart the crond service.

How docker solve the problem that crontab does not take effect

The operating environment of this tutorial: linux7.3 system, docker version 19.03, Dell G3 computer.

How docker solves the problem that crontab does not take effect

The centos image is used by default in docker, and crond is not installed in the image. After successful installation through yum, crontab does not take effect.

1. First check whether /etc/init.d/crond status in the container is in the running state.

If the solution cannot be solved through the first step, refer to the following method:

2. Modify the /etc/pam.d/crond file, change required to sufficient, and then restart crond Service: /etc/init.d/crond restart

How docker solve the problem that crontab does not take effect

Note: This problem does not seem to exist in the centos7 base image.

Expand knowledge

Earliest solution

1. In the host machine

1 3 * * * root cd /data/wwwroot/xxx && docker-compose exec app php think xxx >> /var/log/crontab_xxx.log

docker- compose exec app php think xxx has been unsuccessfully executed

2. Then install crontab in the container, but the execution still fails. The key is that there is no relevant log. Check that crontab is also started. /etc/init.d/cron status

3. Install rsyslog, apt-get install rsyslog, service rsyslog start

View /var/log/syslog

Dec 25 09:07:07 1a8e4fd5c766 crontab[15120]: (root) BEGIN EDIT (root) Dec 25 09:07:34 1a8e4fd5c766 crontab[15120]: (root) REPLACE (root) Dec 25 09:07:34 1a8e4fd5c766 crontab[15120]: (root) END EDIT (root) Dec 25 09:08:01 1a8e4fd5c766 cron[15100]: (root) RELOAD (crontabs/root) Dec 25 09:08:01 1a8e4fd5c766 CRON[15133]: Cannot make/remove an entry for the sp

4. Modify /etc/pam.d/cron

Comment out session required pam_loginuid.so

5. Restart cron and run successfully

Also, change this line Added to dockerfile

RUN sed -i '/session required pam_loginuid.so/c\#session required pam_loginuid.so' /etc/pam.d/crond

There is also a pitfall in crontab execution. There is no problem in manually executing the script because the environment variables are read and PHP needs to write the absolute path

/usr/local/bin/php think xxx

Recommended study: "docker video tutorial

The above is the detailed content of How docker solve the problem that crontab does not take effect. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn