【发布时间】:2018-12-26 05:09:15
【问题描述】:
尝试运行具有 cron 调度的 docker 容器。但是我不能让它输出日志。
我正在使用 docker-compose。
docker-compose.yml
---
version: '3'
services:
cron:
build:
context: cron/
container_name: ubuntu-cron
cron/Dockerfile
FROM ubuntu:18.10
RUN apt-get update
RUN apt-get update && apt-get install -y cron
ADD hello-cron /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
# Run the command on container startup
CMD cron && tail -F /var/log/cron.log
cron/hello-cron
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
上面运行良好,它在容器内输出日志,但是它们没有流式传输到 docker。
例如
docker logs -f ubuntu-cron 返回空结果
但是
如果您登录到容器 docker exec -it -i ubuntu-cron /bin/bash,则您有日志。
cat /var/log/cron.log
Hello world
Hello world
Hello world
现在我想也许我不需要登录到文件?可以将此附加到sttoud,但不确定如何执行此操作。
这看起来很相似... How to redirect cron job output to stdout
【问题讨论】:
标签: docker logging cron docker-compose tty