Hi, I’m very new to Docker and wanted to make sure I am on the right path before diving in too deep.
I am moving my main desktop from Debian Wheezy (#!) to Arch Linux. One of the items I need to port over is a cron script that uses a utility called ledger to mine data from a GnuCash file, generate charts of spending vs budget, and emails them to my wife and I each morning. The latest version of ledger (and the only one available for Arch) does not support GnuCash files any longer, and I must install an older version which is still supported in terms of libraries on Wheezy.
I cannot get it to run in Arch. I don’t want this issue to be a blocking point. I am wondering if I can use Docker to run this script with it’s dependencies in a Wheezy-based Docker container. I think I would need to:
Get a Wheezy container installed
Install ledger 2.6 with proper dependencies
Map a local drive (containing my GnuCash data file) in the container so I can access it
Map a local drive for outputting the images.
Execute the script via Docker with my host cron
The script also sends the email via Gmail. Not sure if I would want to keep that in the container or just let Docker handle the stuff I can’t do in Arch and keep the rest there.
If anybody more experienced can weigh in on the suitability and feasibility of this, it would be much appreciated. Any tips would be even better. For now I’m poring through the docs.
Your cron script on the host could call ledger using the docker run command, and then email the results. You could also do the email bit inside the container.
Pulled debian:wheezy, entered it with /bin/bash and installed ledger and vim. Committed it. Figured out my drive mapping and it runs like a champ! Just need to coordinate the cron between what I put in the image and what runs outside. I’ll search on how to create / use the right user in the image so the files I spit out aren’t owned by root.
This is fantastic technology! I can stay bleeding edge with Arch without giving up the old and stable. Thanks again for your help.
One final note, everything works but it took me 45 minutes of Googling to figure out why my docker run command would not execute with cron, and would leave no trace in the logs.
I had to remove the -t option from my command if starting with cron. With the -t in there, it would fail without any trace. Everything I found when searching was related to running cron INSIDE a container, but nothing addressing executing a docker command within the host cron.
Ah yes, the -t option allocates a pseudo-tty, which cron does not have. If I do something like echo | docker run -it ubuntu cat, it will complain and say FATA[0000] cannot enable tty mode on non tty input. I’m not sure why cron wouldn’t have the same error message though.