pre_start hooks: per_replica: true is accepted by the schema but always rejected at runtime
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
调研方向
The issue is in pkg/compose/pre_start.go where runPreStart validates hooks. The compose-spec model is in types/hooks.go. To implement, examine the reconciliation-plan work in #14221, specifically planPreStartHookRunners. Need to modify the planning to create one runner per hook per replica, adjust naming/labeling (e.g., com.docker.compose.hook-index), resolve VolumesFrom per replica, and update execution in execPreStartHook. Start by reading the existing validation and the skipped planning logic.
由索引模型根据 Issue 内容生成。
描述
What this issue is about
pre_start hooks support a per_replica attribute in the compose-spec model (types.PreStartHook.PerReplica, compose-go's types/hooks.go): "runs the hook once per service replica instead of once per service." docker/compose's engine, however, does not implement it: runPreStart (pkg/compose/pre_start.go) validates every declared hook up front and rejects the whole service if any hook sets per_replica: true:
for i, hook := range service.PreStart {
if hook.PerReplica {
return fmt.Errorf("service %q pre_start[%d]: per_replica is not yet supported; remove per_replica or set it to false", service.Name, i)
}
}
So today, per_replica: true is accepted by the loader/schema but always a hard error at runtime — there is no path to actually use it.
Illustration
services:
app:
image: alpine
command: sleep infinity
deploy:
replicas: 3
pre_start:
- image: alpine
command: ["sh", "-c", "echo initializing replica"]
per_replica: true
$ docker compose up -d
service "app" pre_start[0]: per_replica is not yet supported; remove per_replica or set it to false
The only way to get this compose file to run at all today is to drop per_replica: true, at which point the hook runs once for the whole service (against the lowest-numbered replica only, per the current one-hook-one-runner model) instead of once per replica — a different, sometimes unacceptable behavior for hooks that need to prepare per-replica state (e.g. per-replica config files, per-replica volume initialization).
Suggested scope for an implementation
The reconciliation-plan work in #14221 (pre_start hook runners as first-class plan resources) planned one CreateHookContainer operation per declared hook, targeted at a single resolved replica. Supporting per_replica: true would mean planning one runner per hook × per replica instead, with:
- a deterministic name/label scheme distinguishing replicas (e.g. extending the existing
com.docker.compose.hook-indexlabel with a replica index, or a dedicated label), VolumesFromresolved against that replica rather than the lowest-numbered one,- the corresponding execution-phase change in
runPreStart/execPreStartHookto run and account for one runner per replica.
This issue only tracks the feature gap; the reconciliation-plan groundwork from #14221 already discussed and worked around it (see its planPreStartHookRunners, which explicitly skips planning entirely for a service with any per_replica: true hook, to avoid orphaning runners that could never execute).
- 主要语言
- Go
- 星标
- 38.4k
- 派生
- 5.9k
- 平均合并
- 2 天 2 小时
- 30 天内合并 PR
- 66
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
docker/compose 的其他 Issue
-
[BUG] `docker compose run` drops the anonymous volumes of a dependency it recreates可能已有人在做 @htoyoda18 于 2 天前认领。 未关闭kind/bug status/0-triage
难度 3/5 1-2 天 新手友好度 25/100
维护者通常 1 天内回复
-
kind/feature status/0-triage
难度 5/5 一周以上 新手友好度 35/100
维护者通常 1 天内回复
-
[BUG] <title>未关闭kind/bug status/0-triage
难度 5/5 一周以上 新手友好度 10/100
维护者通常 1 天内回复
-
Epic: Move service selection into the backend API instead of pre-filtering the project in the CLI未关闭
难度 5/5 一周以上 新手友好度 15/100
维护者通常 1 天内回复
-
Watch: exec mode可能已有人在做 @glours 于 7 天前认领。 未关闭kind/feature
docker/compose#14326 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
blinklabs-io/dingo#5368 ·
维护者通常 1 天内回复
-
difficulty: easy enhancement frontend good first issue help wanted priority: P2
难度 2/5 1-3 小时 新手友好度 78/100
rafaelsilvabr/pdfHandler#18 ·
-
难度 2/5 1-2 天 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复