Korzystanie Döcker for Mac 1.13.1 z następującym Dockerfile:Wyjście `ogona -f` w końcu dokowanym CMD nie wykazujące
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
z plikiem contab z:
* * * * * 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
Kiedy zbudować i uruchomić go z:
docker build -t docker-cron-master .
docker run docker-cron-master
widzę wyjście:
docker run docker-cron-master
starting
continuing
tailing...
Jeśli zaczekaj minutę, dane wyjściowe tail -f
nie zostaną wyświetlone. Jednak jeśli mogę się zalogować do uruchomionej pojemnika i ogona pliku widzę zawartość:
$ docker exec -it 4eda6b1fc6ce bash
[email protected]:/# 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
Próbowałem, dodając kolejne echo na końcu CMD, aby zobaczyć, czy to tylko ostatnia komenda kto STDOUT był połknięciu ale to nie pomogło.
Pisałem kod znajduje się na github na https://github.com/simbo1905/docker-cron
Dzięki!
Uruchom swój program główny (ogon) za pomocą 'exec' w przeciwnym razie nie otrzyma sygnałów Ctrl-C (quit). To może również rozwiązać twój problem. '&& exec tail -f ..' – Alkaline