首页 > 解决方案 > 为什么我的 Docker 容器没有运行我的 cron 脚本,但是当我重新启动服务 cron 时它运行了?

问题描述

当我进入我的容器时,Cron 不是一个正在运行的进程,但是当进入容器并 bashservice cron restart它开始运行时,我不明白为什么这不能与 the 一起使用service cron restart但不是没有它?

Dockerfile

FROM ubuntu:bionic

RUN apt-get update && apt-get -y install \ 
    cron \
    nano \
    psmisc \
    wget

COPY hello-cron /etc/cron.d/hello-cron

# Give execution rights on the cron job
RUN chmod +x /etc/cron.d/hello-cron

# Apply cron job
RUN crontab /etc/cron.d/hello-cron

# Create the log file to be able to run tail
CMD ["cron", "-f"]

我的 hello-cron 脚本

* * * * * echo "Hello world" > /usr/src/helloworldcron.log 2>&1

标签: dockercron

解决方案


推荐阅读