Linux Docker容器:Cronjobs未启动(定义我的错误)

Linux Docker容器:Cronjobs未启动(定义我的错误),linux,docker,cron,dockerfile,Linux,Docker,Cron,Dockerfile,我利用现在的时间来发展自己,我决定在Docker容器上投入一些时间 我为自己做了一些小的学习练习,我现在正在做这些练习 我的工作有问题。它应该是一个每分钟都在运行的cronjob。完成脚本的运行时间大约为40-50秒。因此,我决定不每分钟启动一个容器,我希望保持容器运行,并在容器内运行cronjobs 我的问题:Cronjob没有启动 #Dockerfile FROM ubuntu RUN apt-get update RUN apt-get -yq install cron COPY scri

我利用现在的时间来发展自己,我决定在Docker容器上投入一些时间

我为自己做了一些小的学习练习,我现在正在做这些练习

我的工作有问题。它应该是一个每分钟都在运行的cronjob。完成脚本的运行时间大约为40-50秒。因此,我决定不每分钟启动一个容器,我希望保持容器运行,并在容器内运行cronjobs

我的问题:Cronjob没有启动

#Dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get -yq install cron
COPY scripts/cmd.txt /home/cmd.sh
RUN chmod 744 /home/cmd.sh
COPY scripts/cron.txt /etc/cron.d/test-cron
RUN chmod 644 /etc/cron.d/test-cron
RUN crontab /etc/crontab.d/test-cron
RUN touch /var/log/cron.log
CMD cron && tail -f /var/log/cron.log

# scripts/cmd.txt
echo "test aus CMD" >> /var/log/cron.log

# scripts/cron.txt
* * * * * root /home/cmd.sh >> /var/log/cron.log 2>&1
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
据我所知,/var/log/cron.log应该随着时间的推移获得一些内容,但什么也没有发生。我很确定是我造成了这个错误,但我没有找到它

有人知道我做错了什么吗

谢谢和亲切的问候
霍尔格

您的文件中有一些打字错误

#Dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get -yq install cron
COPY scripts/cmd.txt /home/cmd.sh
RUN chmod 744 /home/cmd.sh
COPY scripts/cron.txt /etc/cron.d/test-cron
RUN chmod 644 /etc/cron.d/test-cron
RUN crontab /etc/crontab.d/test-cron # Here it is, just replace `crontab.d` by `cron.d`
RUN touch /var/log/cron.log
CMD cron && tail -f /var/log/cron.log

# scripts/cron.txt
* * * * * root /home/cmd.sh >> /var/log/cron.log 2>&1 # Remove the `root` command from this line...
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1 # ...and also from that one

谢谢你的反馈。我调整了更改并创建了一个新容器。不幸的是,它仍然不起作用。如果您执行docker运行并等待2分钟,您的终端中是否有任何错误或警告?我尝试了docker运行和docker启动,但终端中没有任何内容。