Can I run a cronjob in a MySQL docker container?

8/17/2020

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?

-- jkeeraa
containers
docker
docker-compose
dockerfile
kubernetes

1 Answer

8/18/2020

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
Source: StackOverflow