compose/pkg/compose
Nicolas De Loof ef277d266b pre_start: inherit the whole container specification generically
pre_start hooks carry the full container specification, but the
init-container runner only consumed a handful of attributes (image,
command, user, env, workdir) — everything else was silently dropped.

Instead of wiring attributes one by one, the hook's specification is
merged over the service's ContainerSpec through compose-go's own file
merge machinery (override.Merge on the canonical yaml tree): command
and entrypoint replace, environment merges per key with the hook
winning, extra_hosts and dns accumulate entries, ulimits merge — the
exact per-attribute rules of multi-file compose, maintained in one
place. Every ContainerSpec attribute inherits this way, current and
future, with zero attribute-specific code.

The merged spec then runs through the standard create path
(getCreateConfigs) as a service-shaped one-off, so resources,
capabilities, dns, sysctls, logging... materialize exactly as they
would for a service container. Hook containers keep their minimal
labels and carry no container-number, so tooling telling replicas
apart does not count them.

The only deliberate exception is volumes: mounts inherit at runtime
through volumes_from — the only mechanism that shares the service's
anonymous and image volumes — and the hook's own volume declarations,
materialized by the standard path, take precedence per target. This is
what lets an init container get read-write access to a volume the
service mounts read-only (fixes: see PR).

e2e scenarios lock extra_hosts inheritance and accumulation, volume
override and completion, and the unit tests pin the merge rules.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-09-21 16:35:20 +02:00
..
testdata
transform chore: explicit, unique, greppable names for internal identifiers 2026-08-20 11:17:11 +02:00
api_versions.go fix: gate extra EndpointsConfig behind API >= 1.44 2026-03-31 15:44:00 +02:00
apiSocket.go
attach.go chore: explicit, unique, greppable names for internal identifiers 2026-08-20 11:17:11 +02:00
attach_service.go golangci-lint: use gci formatter instead of goimports 2025-12-01 12:21:50 +01:00
build.go remove buildx as a Go dependency 2026-08-25 17:27:26 +02:00
build_bake.go golangci-lint: enable perfsprint linter 2026-09-10 10:25:34 +02:00
build_bake_test.go fix(build): honor provenance/sbom false in per-service bake attest 2026-08-25 17:46:03 +02:00
build_classic.go golangci-lint: enable perfsprint linter 2026-09-10 10:25:34 +02:00
build_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
commit.go golangci-lint: enable perfsprint linter 2026-09-10 10:25:34 +02:00
compose.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
container.go go.mod: bump github.com/moby/moby/api v1.53.0, moby/client v0.2.2 2026-02-11 12:32:37 +01:00
containers.go chore(compose): orphan semantics stated where up and down diverge 2026-08-31 17:09:19 +02:00
containers_test.go chore(compose): orphan semantics stated where up and down diverge 2026-08-31 17:09:19 +02:00
convert.go go.mod: bump github.com/moby/moby/api v1.53.0, moby/client v0.2.2 2026-02-11 12:32:37 +01:00
cp.go feat(provider): publish-endpoint deploys a network relay for provider services 2026-09-16 17:03:23 +02:00
create.go golangci-lint: enable perfsprint linter 2026-09-10 10:25:34 +02:00
create_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
dependencies.go refactor: NewGraph stops mutating the project 2026-09-01 10:19:10 +02:00
dependencies_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
desktop.go refactor: drop Desktop beta-settings check; gate hint on LogsTab flag 2026-05-18 17:28:03 +02:00
docker_cli_providers.go
down.go fix(provider): guard down's stopContainer against the relay too 2026-09-17 17:51:23 +02:00
down_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
envresolver.go
envresolver_test.go
events.go go.mod: bump github.com/moby/moby/api v1.53.0, moby/client v0.2.2 2026-02-11 12:32:37 +01:00
exec.go feat(provider): publish-endpoint deploys a network relay for provider services 2026-09-16 17:03:23 +02:00
executor.go executor: split into ops + events files 2026-06-08 20:14:38 +02:00
executor_events.go executor: split into ops + events files 2026-06-08 20:14:38 +02:00
executor_ops.go chore: explicit, unique, greppable names for internal identifiers 2026-08-20 11:17:11 +02:00
executor_test.go golangci-lint: enable perfsprint linter 2026-09-10 10:25:34 +02:00
export.go golangci-lint: enable perfsprint linter 2026-09-10 10:25:34 +02:00
filters.go feat(hooks): clean up retained pre_start containers on compose down 2026-08-20 18:57:02 +02:00
generate.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
hash.go fix(reconcile): preserve zero-replica services during hashing 2026-07-16 15:19:50 +02:00
hash_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
hook.go feat(hooks): clean up retained pre_start containers on compose down 2026-08-20 18:57:02 +02:00
hook_spec.go pre_start: inherit the whole container specification generically 2026-09-21 16:35:20 +02:00
hook_spec_test.go pre_start: inherit the whole container specification generically 2026-09-21 16:35:20 +02:00
hook_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
image_pruner.go fix(down): spare dangling images of orphaned services, like their tagged image 2026-09-03 16:00:29 +02:00
image_pruner_test.go fix(down): spare dangling images of orphaned services, like their tagged image 2026-09-03 16:00:29 +02:00
images.go chore: explicit, unique, greppable names for internal identifiers 2026-08-20 11:17:11 +02:00
images_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
kill.go refactor(compose): extract forEachContainerConcurrent to deduplicate pause/kill logic 2026-05-12 11:31:40 +02:00
kill_test.go refactor: fix lint issues from cleanup changes 2026-05-12 11:31:40 +02:00
loader.go feat(compose): warn on unsupported compose-file attributes 2026-09-09 16:32:04 +02:00
loader_test.go fix mixed assertion libraries in tests 2026-03-31 17:32:51 +02:00
logs.go refactor: flatten Ps, restart and Logs orchestration 2026-08-18 13:37:48 +02:00
logs_test.go refactor: fix lint issues from cleanup changes 2026-05-12 11:31:40 +02:00
ls.go chore: explicit, unique, greppable names for internal identifiers 2026-08-20 11:17:11 +02:00
ls_test.go go.mod: bump github.com/moby/moby/api v1.53.0, moby/client v0.2.2 2026-02-11 12:32:37 +01:00
model.go golangci-lint: enable perfsprint linter 2026-09-10 10:25:34 +02:00
monitor.go feat(provider): publish-endpoint deploys a network relay for provider services 2026-09-16 17:03:23 +02:00
monitor_test.go fix: detect externally stopped and removed containers in up monitor 2026-09-16 07:54:38 +02:00
observed_state.go chore(compose): orphan semantics stated where up and down diverge 2026-08-31 17:09:19 +02:00
observed_state_test.go chore(compose): orphan semantics stated where up and down diverge 2026-08-31 17:09:19 +02:00
pause.go refactor(compose): extract forEachContainerConcurrent to deduplicate pause/kill logic 2026-05-12 11:31:40 +02:00
plan.go feat(reconcile): best-effort old-network removal on rename 2026-07-27 14:56:25 +02:00
plan_test.go tests: cover depends_on chaining and OpRunProvider stringer 2026-06-08 20:14:38 +02:00
plugins.go fix(provider): guard pre_start against the relay too, address review nits 2026-09-17 17:51:23 +02:00
plugins_control_test.go feat(provider): get-service-config provider request 2026-09-08 14:53:14 +02:00
plugins_test.go fix: stop-only metadata no longer drops options for up/down 2026-05-18 11:11:38 +02:00
port.go PRIVATE_PORT optional for docker compose port 2026-09-11 11:35:18 +02:00
port_test.go fix(port): preserve tie order for dual-stack port publishers 2026-09-14 10:48:03 +02:00
pre_start.go pre_start: inherit the whole container specification generically 2026-09-21 16:35:20 +02:00
pre_start_test.go pre_start: inherit the whole container specification generically 2026-09-21 16:35:20 +02:00
printer.go next release will be major version v5.x 2025-11-13 09:32:43 +01:00
progress.go fix: restore stoppingEvent/stoppedEvent helpers for plugin stop hook 2026-05-18 15:12:39 +02:00
ps.go fix(port): preserve tie order for dual-stack port publishers 2026-09-14 10:48:03 +02:00
ps_test.go refactor: fix lint issues from cleanup changes 2026-05-12 11:31:40 +02:00
publish.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
publish_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
pull.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
pull_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
push.go registry: encode credentials with moby's authconfig package 2026-08-25 17:27:26 +02:00
rebuild_scheduler.go fix(watch): interrupt stale rebuilds so watch converges 2026-09-14 10:47:07 +02:00
rebuild_scheduler_test.go fix(watch): interrupt stale rebuilds so watch converges 2026-09-14 10:47:07 +02:00
reconcile.go golangci-lint: enable perfsprint linter 2026-09-10 10:25:34 +02:00
reconcile_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
relay.go fix(provider): drop the relay's capabilities to the strict minimum 2026-09-17 17:51:23 +02:00
relay_test.go fix(provider): drop the relay's capabilities to the strict minimum 2026-09-17 17:51:23 +02:00
remove.go golangci-lint: enable perfsprint linter 2026-09-10 10:25:34 +02:00
restart.go fix(provider): clean up stale relay and guard start/restart against it 2026-09-17 17:51:23 +02:00
restart_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
run.go fix(display): harden termWriter lifecycle against review findings on #14119 2026-09-09 16:50:05 +02:00
scale.go api: ScaleOptions carries the replica counts it always pretended to 2026-08-20 10:16:06 +02:00
scale_test.go api: ScaleOptions carries the replica counts it always pretended to 2026-08-20 10:16:06 +02:00
secrets.go chore: inline needless single-use helpers 2026-08-14 22:49:53 +02:00
service_containers.go fix(provider): guard pre_start against the relay too, address review nits 2026-09-17 17:51:23 +02:00
service_containers_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
shellout.go go.mod: bump github.com/moby/moby/api v1.53.0, moby/client v0.2.2 2026-02-11 12:32:37 +01:00
start.go refactor: NewGraph stops mutating the project 2026-09-01 10:19:10 +02:00
start_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
stop.go fix(provider): stop reaches the relay container like down already does 2026-09-16 17:03:23 +02:00
stop_test.go go.mod: bump github.com/moby/moby/api v1.53.0, moby/client v0.2.2 2026-02-11 12:32:37 +01:00
top.go go.mod: bump github.com/moby/moby/api v1.53.0, moby/client v0.2.2 2026-02-11 12:32:37 +01:00
unsupported_attributes.go feat(compose): warn on unsupported compose-file attributes 2026-09-09 16:32:04 +02:00
unsupported_attributes_test.go feat(compose): warn on unsupported compose-file attributes 2026-09-09 16:32:04 +02:00
up.go fix(up): drop benign context.Canceled noise from the final report 2026-09-16 13:54:05 +02:00
up_test.go fix(up): drop benign context.Canceled noise from the final report 2026-09-16 13:54:05 +02:00
viz.go chore: explicit, unique, greppable names for internal identifiers 2026-08-20 11:17:11 +02:00
viz_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00
volumes.go chore: explicit, unique, greppable names for internal identifiers 2026-08-20 11:17:11 +02:00
volumes_test.go go.mod: bump github.com/moby/moby/api v1.53.0, moby/client v0.2.2 2026-02-11 12:32:37 +01:00
wait.go go.mod: bump github.com/moby/moby/api v1.53.0, moby/client v0.2.2 2026-02-11 12:32:37 +01:00
watch.go fix(watch): interrupt stale rebuilds so watch converges 2026-09-14 10:47:07 +02:00
watch_test.go build(deps): adopt compose-go jobs and the container-spec layering 2026-09-21 16:35:20 +02:00