Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

pre_start hooks: per_replica: true is accepted by the schema but always rejected at runtime

未关闭
#14,259 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
docker, docker-compose, go
领域
cli, devops, tooling

调研方向

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-index label with a replica index, or a dedicated label),
  • VolumesFrom resolved against that replica rather than the lowest-numbered one,
  • the corresponding execution-phase change in runPreStart/execPreStartHook to 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

docker/compose 的其他 Issue

查看 docker/compose 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。