compose-scheduler icon indicating copy to clipboard operation
compose-scheduler copied to clipboard

How to avoid running a job at "docker compose up"?

Open sprat opened this issue 2 years ago • 4 comments

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?

sprat avatar Aug 18 '23 09:08 sprat

See compose profiles. Those might be helpful.

luolong avatar Feb 16 '24 07:02 luolong

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 avatar Feb 16 '24 09:02 sprat

@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 avatar Dec 22 '24 20:12 rare-magma

@rare-magma, that's an interesting idea, i will try this technique when I'll get back to my project. Thanks for the input!

sprat avatar Dec 23 '24 11:12 sprat