Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sprat opened this issue Aug 18, 2023 · 4 comments
Open

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

sprat opened this issue Aug 18, 2023 · 4 comments

Comments

@sprat
Copy link

sprat commented Aug 18, 2023

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?

@luolong
Copy link

luolong commented Feb 16, 2024

See compose profiles. Those might be helpful.

@sprat
Copy link
Author

sprat commented Feb 16, 2024

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.

@rare-magma
Copy link
Contributor

rare-magma commented Dec 22, 2024

@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

@sprat
Copy link
Author

sprat commented Dec 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants