Cron fails to execute docker because exec adds the -it parameter. The solution is to correct "docker exec php-7.2_1 /bin/bash -c 'cd /usr/local/nginx/html/MyProject. ..” That’s it.
The operating environment of this article: ubuntu16.04 system, Docker 20.10.11, Dell G3 computer.
How to solve the problem of cron failing to execute docker?
crontab failed to execute docker exec command:
Original script--> failed
#!/bin/bash docker exec -it php-7.2_1 /bin/bash -c 'cd /usr/local/nginx/html/MyProject && sh GatherData.sh'
Correction--> Success
#!/bin/bash docker exec php-7.2_1 /bin/bash -c 'cd /usr/local/nginx/html/MyProject && sh GatherData.sh'
Cause of failure
Adding the -it parameter to exec opens a terminal, and the scheduled task cannot enter any terminal.
Recommended learning: "docker video tutorial"
The above is the detailed content of How to solve the problem of cron executing docker failure. For more information, please follow other related articles on the PHP Chinese website!