Попробуйте использовать том:
ьзование Docker для Mac 1.13.1 со следующим Dockerfile:
FROM ubuntu:latest
MAINTAINER [email protected]
#Install packages and clean downloaded packages in the lowest layer
RUN apt-get update && apt-get -y install cron && rm -rf /var/lib/apt/lists/*
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron
# Give execution rights on the cron job and create the log file to tail in the next layer
RUN chmod 0644 /etc/cron.d/hello-cron && touch /var/log/cron.log
# Run the command on container startup
CMD echo "starting" && echo "continuing" && (cron) && echo "tailing..." && tail -f /var/log/cron.log
С файлом contab:
* * * * * root echo "Hello world `date`" >> /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
Когда я собираю и запускаю его с:
docker build -t docker-cron-master .
docker run docker-cron-master
Я вижу вывод:
docker run docker-cron-master
starting
continuing
tailing...
Если я подожду минутуtail -f
вывод не появляется. Тем не менее, если я войду в работающий контейнер и подключу файл, я смогу увидеть его содержимое:
$ docker exec -it 4eda6b1fc6ce bash
root@4eda6b1fc6ce:/# tail -f /var/log/cron.log
Hello world Fri May 5 09:53:01 UTC 2017
Hello world Fri May 5 09:54:01 UTC 2017
Я попытался добавить еще одно эхо в конце CMD, чтобы посмотреть, была ли проглочена только последняя команда, которая STDOUT проглотила, но это не помогло.
Я разместил код на GitHub вhttps://github.com/simbo1905/docker-cron
Спасибо!