Using Docker for Mac 1.13.1 with the following Docker file:
FROM ubuntu:latest
MAINTAINER docker@ekito.fr
RUN apt-get update && apt-get -y install cron && rm -rf /var/lib/apt/lists/*
ADD crontab /etc/cron.d/hello-cron
RUN chmod 0644 /etc/cron.d/hello-cron && touch /var/log/cron.log
CMD echo "starting" && echo "continuing" && (cron) && echo "tailing..." && tail -f /var/log/cron.log
With the contab file:
* * * * * root echo "Hello world `date`" >> /var/log/cron.log 2>&1
When I create and run it with:
docker build -t docker-cron-master .
docker run docker-cron-master
I see the result:
docker run docker-cron-master
starting
continuing
tailing...
If I wait a minute, the output tail -f
will not appear. However, if I enter the running container and the tail of the file, I can see the contents:
$ docker exec -it 4eda6b1fc6ce bash
root@4eda6b1fc6ce:/
Hello world Fri May 5 09:53:01 UTC 2017
Hello world Fri May 5 09:54:01 UTC 2017
I tried adding another echo at the end of the CMD to make sure that this was only the last command that STDOUT swallowed, but that did not help.
I posted the code on github at https://github.com/simbo1905/docker-cron
Thanks!
source
share