提问人:Arrow 提问时间:11/16/2023 更新时间:11/16/2023 访问量:13
Cronjob 未在 docker 容器内运行
Cronjob not running inside docker container
问:
我有python脚本,我想使用crontab上添加的shell脚本在docker容器中执行。 我创建了以下dockerfile:
FROM python:3.10.12
# create directory for logs
RUN mkdir /logs
# create a folder and copy code to it
WORKDIR /app
COPY . /app
# make python and shell script executable
RUN find . -name "*.py" -exec chmod +x {} \;
RUN find . -name "*.sh" -exec chmod +x {} \;
# install dependencies
RUN apt-get -y update && apt-get install -y default-libmysqlclient-dev
RUN pip install -r requirements.txt
RUN apt-get update && apt-get install -y cron && apt-get install -y vim
# Copy the cron file to the container
COPY cronfile.cronjob /etc/cron.d/cronfile.cronjob
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/cronfile.cronjob
# Apply the cron job
RUN crontab /etc/cron.d/cronfile.cronjob
# create log file
RUN touch /var/log/cron.log
# start the cron daemon
CMD ["cron", "-f"]
以下是 cronfile.cronjob 内容:
* * * * * echo "Hello world" `date` >> /var/log/cron.log 2>&1
40 19 * * * /app/crons/test.sh >> /var/log/cron.log 2>&1
在app/crons目录中,我有 test.sh shell脚本。
当我使用命令检查 cron servive 时:它显示运行状态。
使用命令时:它在 crontab 中显示 cronfile.cronjob 内容
但是 cronjobs 仍然没有执行。service cron status
crontab -l
无法理解这里的问题。
我希望 cron 执行 cronfile.cronjob 中提到的 cronjobs。 我已经尝试了很多方法,但无法理解这个问题 我尝试了以下链接帮助资源,但没有任何效果。解决方案 1 解决方案 2 解决方案 3
答: 暂无答案
评论