Add pre_start lifecycle hook for init containers#647
Merged
ndeloof merged 1 commit intoJun 16, 2026
Conversation
Introduce pre_start as a sequence of init containers run before a service starts. Each step runs to completion in declared order, in its own ephemeral container created after ContainerCreate but before ContainerStart, with the service container's mounts shared. A non-zero exit fails the bring-up of the service and its dependents. This is the first-class replacement for the restart: "no" plus service_completed_successfully pattern. Signed-off-by: Guillaume Lours <[email protected]> Signed-off-by: Guillaume Lours <[email protected]>
glours
force-pushed
the
init-containers-pre-start-proposal
branch
from
June 16, 2026 08:49
2b4e69f to
2c4838d
Compare
ndeloof
approved these changes
Jun 16, 2026
glours
added a commit
to glours/compose-go
that referenced
this pull request
Jun 16, 2026
Implements the `pre_start` service field introduced in compose-spec/compose-spec#647: an ordered list of init containers run to completion before the service container starts. Each step runs in its own ephemeral container; a non-zero exit fails the bring-up of the service and its dependents. Compose-go owns parsing, validation via JSON schema, and image inheritance: when a pre_start hook omits `image`, it is normalized to the parent service's image. Volume/network inheritance and the runtime execution stay with docker/compose. Signed-off-by: Guillaume Lours <[email protected]>
3 tasks
glours
added a commit
to glours/compose-go
that referenced
this pull request
Jun 29, 2026
Implements the `pre_start` service field introduced in compose-spec/compose-spec#647: an ordered list of init containers run to completion before the service container starts. Each step runs in its own ephemeral container; a non-zero exit fails the bring-up of the service and its dependents. Compose-go owns parsing, validation via JSON schema, and image inheritance: when a pre_start hook omits `image`, it is normalized to the parent service's image. Volume/network inheritance and the runtime execution stay with docker/compose. Signed-off-by: Guillaume Lours <[email protected]>
glours
added a commit
to compose-spec/compose-go
that referenced
this pull request
Jun 29, 2026
Implements the `pre_start` service field introduced in compose-spec/compose-spec#647: an ordered list of init containers run to completion before the service container starts. Each step runs in its own ephemeral container; a non-zero exit fails the bring-up of the service and its dependents. Compose-go owns parsing, validation via JSON schema, and image inheritance: when a pre_start hook omits `image`, it is normalized to the parent service's image. Volume/network inheritance and the runtime execution stay with docker/compose. Signed-off-by: Guillaume Lours <[email protected]>
|
It's really great to see the progress on init containers in docker compose and the spec. Awesome work! 👍 I designed something very similar as a |
aevesdocker
added a commit
to docker/docs
that referenced
this pull request
Jul 2, 2026
<!--Delete sections as needed --> ## Description As per docker/compose#13862 and compose-spec/compose-spec#647 ## Related issues or tickets <!-- Related issues, pull requests, or Jira tickets --> ## Reviews <!-- Notes for reviewers here --> <!-- List applicable reviews (optionally @tag reviewers) --> - [ ] Technical review - [ ] Editorial review - [ ] Product review --------- Co-authored-by: Guillaume Lours <[email protected]>
glours
added a commit
that referenced
this pull request
Jul 17, 2026
… triggers Follow-up to #647, addressing gaps identified while implementing the hook: - state explicitly that pre_start steps only run once the service's depends_on conditions have been satisfied - define per_replica: true semantics: one run per replica, tied to that replica's mounts and start; declared order preserved per replica, runs for distinct replicas may execute concurrently; a failed run prevents that replica from starting and fails the service bring-up - state that per_replica: false on a scaled service is not an error when per-instance mounts exist; such steps simply run without access to them - define "definition changes" (any attribute) and "service is recreated" (container recreation: config change, forced recreate) as re-run triggers - replace the tmpfs example on per_replica: volume sharing relies on volumes_from, which does not propagate tmpfs mounts - fix broken post_start link in the pre_stop section Signed-off-by: Guillaume Lours <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
Introduce
pre_startas a sequence of init containers run before a service starts.Each step runs to completion in declared order, in its own ephemeral container created after
ContainerCreatebut beforeContainerStart, with the service container's mounts shared. A non-zero exit fails the bring-up of the service and its dependents.This is the first-class replacement for the restart: "no" plus
service_completed_successfullypattern.Which issue(s) this PR fixes:
Follow up of #11