不能将日志文件拖放到Ubuntu容器中的docker日志中

这是一个类似的问题,“ tail -f没有在Docker容器中跟踪日志文件 ”,但我不确定它是否是相同的根本原因。

我试图设置一个简单的cron docker容器,并且已经testing了一堆我能find的例子,包括这个“ https://stackoverflow.com/questions/37458287/how-to-run-a-cron-作业内docker集装箱 “。

FROM ubuntu:latest # Setup cron and scripts... ... # Create the log file to be able to run tail RUN touch /var/log/cron.log # Run the command on container startup CMD cron && tail -f /var/log/cron.log 

问题是,这个工程和cron作业运行,但没有什么会在运行docker run时在docker日志或输出中出现。 是的,我已通过在容器上运行docker exec命令来validation日志文件正在写入。


然后,我testing了从ubuntu:latestubuntu:trusty ,认为它可能与Ubuntu 16有关。这导致在启动容器时出现以下错误:

 tail: unrecognized file system type 0x794c7630 for '/var/log/cron.log'. please report this to [email protected]. reverting to polling 

谷歌search后,我发现了一些错误的build议。 所以我尝试调整我的docker文件,如下所示:

 # RUN touch /var/log/cron.log <-- remove this CMD touch /var/log/cron.log && cron && tail -f /var/log/cron.log 

现在,当我运行这与ubuntu:latest ,似乎工作得很好。 这到底是怎么回事?