How to graceful shutdown docker container while crontab is running?

I’d like to create a container that itself runs a cronjob.
While the cronjob runs, a redeployment of the container should delay the shutdown for X minutes (my job runs at max 10mins).

Deployment in my case means:

docker-compose pull
docker-compose up

Question: how could I achieve a graceful shutdown here?

My first approach was to let the crontab process being the PID1 process. Inspired from here: Running Cron in Docker

But how could I then detect if a cronjob is currently executing (=delay shutdown), or idle (=shutdown immediately) on redeployment?


CMD ["cron", "-f", "-L", "2"]


    init: true

exec "$@"

0/30 * * * * /opt/ >/proc/1/fd/1 2>/proc/1/fd/2


#this script takes a few minutes to execute:
#- copy files from a to b
#- run another .sh script that converts them
#- cleanup files

You can increase the stop timeout: