Skip to content

compose: wait for service_healthy and service_completed_successfully dependencies - #5324

Open
cvas22 wants to merge 1 commit into
containerd:mainfrom
cvas22:feat/compose-depends-on-conditions
Open

cvas22 wants to merge 1 commit into
containerd:mainfrom
cvas22:feat/compose-depends-on-conditions

Conversation

@cvas22

@cvas22 cvas22 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #2386.

nerdctl compose up warned Ignoring: service adminer: depends_on: db: condition service_healthy and started the service as soon as the dependency's container was created. Healthchecks themselves are supported now (--health-cmd, and the compose healthcheck is already mapped), so the condition can be honoured.

Before a service is started, up now waits for the dependencies that declare:

  • service_healthy: polls the health state label of each container of the dependency until it is healthy. It fails if the dependency has no healthcheck, turns unhealthy, or exits first.
  • service_completed_successfully: waits for each container of the dependency to exit and fails on a non-zero exit code.

service_started (the default) is unchanged, and --no-deps skips the waiting. Services were already started in dependency order.

Notes

  • waitContainerHealthy has a unit test with a fake container (healthy, unhealthy, no healthcheck, still starting). I ran it in a Linux container.
  • I added integration tests for service_completed_successfully, both when the dependency succeeds and when it exits with 3. I could only compile them locally (GOOS=linux go vet), so I'm relying on CI to run them.
  • There is no integration test for service_healthy, since the healthcheck timers need systemd. I would be glad to add one if you tell me how you would like it to run in CI.
  • There is no timeout; like docker compose, it waits until the dependency is healthy, fails, or the command is interrupted.

testCase := nerdtest.Setup()

// The error message is nerdctl's.
testCase.Require = require.Not(nerdtest.Docker)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to skip the test. You can just change the string to compare.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash the commits

…dependencies

compose up ignored these depends_on conditions with a warning, so a service could start before its dependency was ready. Wait for them before starting the service: healthy needs a healthcheck on the dependency and fails if it turns unhealthy or exits, completed_successfully fails on a non-zero exit code.

Fixes containerd#2386

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22
cvas22 force-pushed the feat/compose-depends-on-conditions branch from 7b7a0d3 to 9097aa4 Compare November 27, 2026 07:21
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

Successfully merging this pull request may close these issues.

depend_on and healthcheck is ignored when running nerdctl compose up

2 participants