docker / docker/compose

Question: Handling --exit-code-from premature teardown when dependency services exit

Open
#13,800 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
38.2k
Forks
5.8k
Avg merge
2d 14h
Merged PRs (30d)
55

Description

Context

We are developing an IDE integration where users can run their applications via a specific service defined in compose.yml. To correctly capture and display the exit code of the target application in the IDE terminal, we start the application using the following command:

docker compose up --exit-code-from <app-service> <app-service>
The Problem

The --exit-code-from flag implicitly enables --abort-on-container-exit. This causes unintended behavior when the target <app-service> relies on other utility or one-off containers (e.g., linters, database migrations, log collectors, or user exploration sessions).

When one of these dependency containers exits, the implicit --abort-on-container-exit triggers and shuts down the entire stack—including the still-running primary application. This happens regardless of the dependency's exit status. Whether a migration finishes successfully, a linter fails, or a user runs an incorrect custom command in an exploratory container, the primary app is unexpectedly killed.

Workarounds Considered

We considered bypassing --exit-code-from entirely by splitting the execution into multiple commands:

  1. docker compose up -d <app-service>
  2. docker compose logs --follow <app-service>
  3. docker compose down <app-service> (triggered when stopping the application from the terminal)

While this is technically doable, managing multiple asynchronous calls makes the IDE implementation significantly more convoluted and introduces potential race conditions.

Questions
  1. Is this strict abort behavior intended when dependency containers exit, regardless of their exit code or purpose? I would love to understand the design logic behind this.
  2. Are there any recommended, cleaner alternatives to capture the target service's exit code without triggering a full stack teardown when side-services exit?

https://github.com/user-attachments/assets/d6709364-765a-444b-a0eb-6197a8ab8939

Thank you for your time and insights!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the compose.yml scenario with docker compose up --exit-code-from <app-service> <app-service> and a dependency container that exits. Read the behavior of --exit-code-from and its implicit --abort-on-container-exit; done means documenting whether this teardown is intended and identifying a supported way to capture the target service's exit code without stopping the stack.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker-compose
Domain
devops
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.