compose-scheduler
compose-scheduler copied to clipboard
How to avoid running a job at "docker compose up"?
Imagine that I have a long running job, for example a backup sync to an online storage service or a disks scrubing task: I would like to avoid launching the job on docker compose up but wait until the scheduled time arrives (in this case, during the night...).
One way to do that is to define a "do nothing/wait indefinitely" command by default in the service and use the exec mode to run the real command on schedule. But in this case, I cannot invoke the job manually with docker compose run / docker compose start if I need/want to.
So I would prefer using the run mode (which semantically is more a start than a run since no container is created for each run), but I can't find to way to avoid running the container at docker compose up time. And I don't see how it could be implemented either since the tool need a container to start which must have been previously created. But maybe someone will come up with an idea?
See compose profiles. Those might be helpful.
It does not help because when you use compose profiles, no container is created when you docker compose up, but the scheduler expect the container to exist in order to "exec" into it. That's why I raised this ticket.
@sprat I've solved this problem by doing the following:
- Shutdown containers (if running) when unit is started and recreate all containers
docker compose down && docker compose up --no-start - Start compose-scheduler container only
docker compose up scheduler
scheduler above is referring to the name of the compose-scheduler service in my docker compose file
@rare-magma, that's an interesting idea, i will try this technique when I'll get back to my project. Thanks for the input!