I’ve been trying to set cron up within a Docker container. It is now working fine. What I want now is a log file.
This is my crontab:
* * * * * python /code/data_etl.py > /proc/1/fd/1 2> /proc/1/fd/2
My Dockerfile CMD is CMD ["cron", "-f"]
.
I was only able to get this working by following the answer here
How to run a cron job inside a docker container?
I’m not 100% sure, but I believe the f
flag is running cron in the foreground, rather than as a background process.
However, I’m not sure why this line > /proc/1/fd/1 2> /proc/1/fd/2
is really necessary, and therefore, don’t know how to amend it so that I can store a log file in my Docker container.
2
Answers
Good Morning! You should be try to change your parameters in cron file to below:
Only you need one of these, i think is unnecessary use
2> /proc/1/fd/2
Let me know your result! Have a great day!
> /proc/1/fd/1
redirectsstdout
of yourpython
process (your task) tostdout
of the process with PID 1 (which is thecrod
daemon).2> /proc/1/fd/2
redirectsstderr
of your task tostderr
of thecron
daemon.Unless you do that, the output of your task won’t appear in
docker logs
. And this trick works provided you run your tasks asroot
.But doesn’t that seem kind of tricky? Why not use a
docker
-friendlycron
implementation?