在Windows主机上的Docker容器中运行cron

3
我在尝试创建一个运行cronjob的容器时遇到了一些问题。我可以使用top命令在容器中看到cron正在运行,但它不会像下面的示例尝试那样写入日志文件。该文件保持为空。
我已经阅读了以下类似问题的答案: 但我无法使任何建议起作用。例如,我使用了这里的dockerfile:https://github.com/Ekito/docker-cron/
FROM ubuntu:latest
MAINTAINER docker@ekito.fr

# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron

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

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

#Install Cron
RUN apt-get update
RUN apt-get -y install cron


# Run the command on container startup
CMD cron && tail -f /var/log/cron.log

crontab:

* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
# Don't remove the empty line at the end of this file. It is required to run the cron job

我的电脑(Windows 10)无法正常运行。显然,有其他人也报告了一个仅在 Windows 上出现的问题:https://github.com/Ekito/docker-cron/issues/3

为了测试是否仅我操作不当,我尝试在运行 Ubuntu 的虚拟机中执行相同操作(使用Ubuntu主机而非Windows主机),并且按预期工作。日志文件如预期所示被扩展。

那么我该怎么做才能让它正常工作呢?

我尝试写入一个已挂载(绑定)的文件夹,并创建一个卷进行写入。但两者都没有起作用。

2个回答

2

rferalli在github问题中给出的答案对我很有帮助:

“遇到了相同的问题。通过将crontab文件的行结尾从CRLF更改为LF来修复它。希望这可以帮到你!”


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接