[英]can't run cron message inside alpine docker file
我正在嘗試在 docker 容器中啟動一個簡單的 chron 消息來測試 chron:
在我的 php-fpm Dockerfile 里面:
...
RUN echo "* * * * * run-parts /etc/periodic/1min" >> /etc/crontabs/root
RUN mkdir /etc/periodic/1min
COPY cronscript.sh /etc/periodic/1min
RUN chmod a+x /etc/periodic/1min/cronscript.sh
RUN dos2unix /etc/periodic/1min/cronscript.sh
...
CMD [ "crond", "-l", "2", "-f" ]; composer install ; wait-for-it database:3306 -- bin/console doctrine:migrations:migrate ; php-fpm;
我的 cronscript.sh:
#!/usr/bin/env sh
echo "My test message"
當我在容器內運行crontab -e
時,我得到:
當我運行容器時,我沒有收到消息:
如何每 1 分鍾定期正確顯示消息?
您確定將 cron 作業添加到計划中嗎?
cron.txt
之外定義您的工作* * * * * xxx xxx
ADD
命令將計划添加到圖像ADD cron.txt /etc/crontabs/xxx
Dockerfile
FROM alpine
# Copy script which should be run
COPY ./yourscript /usr/local/bin/yourscript
# Run the cron every minute
RUN echo '* * * * * /usr/local/bin/yourscript' > /etc/crontabs/root
CMD ['crond', '-l 2', '-f']
Script
#!/bin/sh
echo "My test message" >> /dev/stdout
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.