[BUG] pre_stop hooks are skipped when up or scale stops a container

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

维护者通常 1 天内回复

@htoyoda18 已经在做这个了。

开始于 2026年11月7日。

  • #14477 来自 @htoyoda18 —— 未关闭

评估

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

调研方向

Start by tracing how Compose stops containers during scale-down, dependent restarts, and network recreation, then compare those paths with docker compose stop, where the issue says pre_stop runs. Use the supplied Compose file and reproduction steps to check each case; done means pre_stop runs and writes the expected line in all three cases.

由索引模型根据 Issue 内容生成。

描述

kind/bug status/approved
Description

Since v5.2.0, pre_stop hooks only run on docker compose stop / down. When up or scale stops a container itself (scale down, restarting a restart: true dependent, recreating a network), the container is stopped without running its pre_stop hooks, and nothing reports it. v5.1.4 runs them in all these cases.

Steps To Reproduce
  1. Create compose.yaml:

    services:
      db:
        image: busybox
        init: true
        command: sleep infinity
        environment:
          V: "1"
      web:
        image: busybox
        init: true
        command: sleep infinity
        volumes:
          - ./log:/log
        depends_on:
          db:
            condition: service_started
            restart: true
        pre_stop:
          - command: sh -c 'echo "pre_stop $$HOSTNAME" >> /log/hooks'
    
  2. mkdir log && touch log/hooks && docker compose up -d --scale web=2

  3. docker compose up -d --scale web=1: web-2 is stopped and removed, but log/hooks stays empty (v5.1.4 writes one line).

  4. Change V of db to "2", then docker compose up -d: db is recreated and web-1 is stopped and started again (restart: true), and still no line is written.

  5. docker compose stop: one line is written, so the hook itself works.

Compose Version
Docker Compose version v5.7.0
Docker Environment

Anything else?

No response

主要语言
Go
星标
38.9k
派生
6k
平均合并
2 天 22 小时
30 天内合并 PR
81

环境准备

从这里开始

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

docker/compose 的其他 Issue

查看 docker/compose 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

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