简体   繁体   中英

Saving cron output to log within Docker container

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.

Good Morning: You should be try to change your parameters in cron file to below

* * * * * python /code/data_etl.py > /proc/1/fd/1

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM