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

Start containers as soon as they are ready #11783

Open
remcokranenburg opened this issue May 1, 2024 · 3 comments
Open

Start containers as soon as they are ready #11783

remcokranenburg opened this issue May 1, 2024 · 3 comments

Comments

@remcokranenburg
Copy link

remcokranenburg commented May 1, 2024

Description

When using docker compose up (or watch), Compose first builds all required images and then starts containers for them. In some workloads, one container is ready to launch much earlier than another.

An example: a postgres container is ready almost immediately, while the backend container is still building. During development, it can be quite useful to already start working with the database.

Would it be possible to launch containers as soon as they are ready, not waiting for all images to be built first?

Some observations:

  • When one service depends_on another, it obviously must wait until the dependency is ready
  • This may not be a desirable behavior in production
  • This feature can be emulated by first starting the 'faster' services: docker compose up --wait database && docker compose up
@ndeloof
Copy link
Contributor

ndeloof commented May 1, 2024

Would be a significant architectural change
Also to be considered: what would be expected if build fails ? Should the already running services be stopped (like when you hit Ctrl+C to stop a compose up command) ?

For the scenario you describe, it seems to me relying on watch feature with a rebuild strategy already covers your need: even first time you run compose up you'll need to wait for build to complete before you can access database, then changes made to your backend source code will trigger a rebuild and restart so you don't have to wait more than required

@remcokranenburg
Copy link
Author

Yes I had a feeling this would not be an easy one, so I definitely don't expect anything unless it is useful for many people!

As said, I can mostly emulate this behavior by doing a smaller up before doing a full up (or watch), so that would solve my initial problem. Your suggestion of using the rebuild strategy doesn't completely cover it: if you open your laptop, do a git pull and then start watch, your colleagues could have changed a lot of code, so you may at any time face waiting for a rebuild that is out of your control.

That becomes especially aggravating when the changes are in a part you don't care about at that moment: you have 10 rebuilding containers, and you just want to work on that one container right now!

In any case, a workaround is available, but it could be more 'hands-off' by starting containers as soon as they are ready.

@remcokranenburg
Copy link
Author

Oh, I found another use case!

Some development containers have quite a long initialization phase: for example the Angular development server compiles source code on-the-fly (for hot-reloading support), but it can only start once the container starts. It would save quite some time if it could already start compiling even though some other services are still in the build phase.

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

No branches or pull requests

2 participants