is it possible to run a cronjob to execute a python script in a MySQL docker conatiner? Or should I create an Ubuntu docker container and install MySQL there?
Asked
Active
Viewed 504 times
0
-
yeah, make your own dockerfile which uses the mysql image you want then (install cron if not installed), ADD your script to the fs, run a cmd to apply the crontab. – Lawrence Cherone Aug 17 '20 at 12:25
-
which cmd is that to set cron? @LawrenceCherone – jkeeraa Aug 17 '20 at 12:32
-
summing like: `CMD crontab -l | { cat; echo "* * * * * /path/to/your/file.py"; } | crontab -` though you could also write directly to one of `/etc/cron.d/*` files – Lawrence Cherone Aug 17 '20 at 12:40
-
This answer may be useful: https://stackoverflow.com/questions/37458287/how-to-run-a-cron-job-inside-a-docker-container – Stefano Fiorucci - anakin87 Aug 18 '20 at 16:10
1 Answers
0
You can run a python script in your MySQL Docker Container. In order to do that you have to install crontab and python client in order to execute the script. It will look something like this:
FROM mysql:latest
RUN apt-get update \
&& apt-get install -y cron python
COPY ./YOUR_SCRIPT.py /YOUR_SCRIPT.py
RUN chmod +x /YOUR_SCRIPT.py #MAKE SCRIPT EXECUTABLE
RUN crontab -l | { cat; echo "* * * * * /YOUR_SCRIPT.py"; } | crontab -
ENTRYPOINT ["/YOUR_SCRIPT.py"]

kool
- 3,214
- 1
- 10
- 26