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

Suport Re-Following Logs on Single Service Restart #10331

Closed
ComfyDust opened this issue Feb 28, 2023 · 4 comments
Closed

Suport Re-Following Logs on Single Service Restart #10331

ComfyDust opened this issue Feb 28, 2023 · 4 comments
Assignees

Comments

@ComfyDust
Copy link

ComfyDust commented Feb 28, 2023

Description

When following logs via docker compose up or docker compose logs -f, the command automatically re-follows container logs when a service is restarted but only if multiple services are running. If only one service is running, the command detaches instead.

It would be handy to have the ability to re-follow logs even if only one service is running (e.g., via a new parameter).

For context, I'm currently writing a CLI wrapper that starts a docker compose application with two services, one of which is optionally activated via a profile. The primary service needs to be periodically restarted. When both services are running, docker compose up automatically reattaches to the container so the wrapper can simply continue printing results from STDOUT. When only one service is running, however, I need to restart the service, wait for it to be up, and re-attach. It would be nice to instead be able to consistently re-follow logs for both scenarios.

@ndeloof
Copy link
Contributor

ndeloof commented Mar 1, 2023

Marking this as a bug, compose can detect service container is restarting, should not exit

@laurazard
Copy link
Contributor

laurazard commented Mar 1, 2023

@ndeloof we had a discussion about this on #10181, it's not that clear (and not a bug unless we want to change behavior from V1).

It works fine when there is a Compose file with multiple services (as logs doesn't exit, the new service starts and we reattach) but this issue is for when the Compose file only has 1 service defined. In that case, if a user runs compose restart [xxx] in another terminal, Compose has no way of knowing if the container will start again or not unless instead of immediately exiting we wait for a bit to see if service starts again.

In the comment in #10181 (comment), you mentioned that restarting is only set by restart policy, so we don't really know if a container is restarting unless it is restarting due to restart policy.

The issue here is what to do when user runs compose logs -f on a Compose file with 1 service defined, and that service exits (due to running compose restart x in another terminal, so restarting is not set and we don't know if container will restart).

@ndeloof
Copy link
Contributor

ndeloof commented Mar 1, 2023

@laurazard I recently introduced a mechanism for compose to know a container is restarted, see #10236

@ndeloof ndeloof self-assigned this Mar 6, 2023
@ndeloof
Copy link
Contributor

ndeloof commented May 3, 2023

As we are stuck with docker engine limitation not to populate State.Restarting as a container is restarted by command, we have no technical way to implement this feature 🥺
I'm closing this issue, will obviously be reconsidered if something changes on Docker engine.

@ndeloof ndeloof closed this as completed May 3, 2023
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

3 participants