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

Đang mở
#14,476 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@htoyoda18 đang làm issue này rồi.

Từ ngày 7/11/2026.

  • #14477 của @htoyoda18 — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
53/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
docker-compose, go
Lĩnh vực
devops

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Go
Star
38.9k
Fork
6k
Merge trung bình
2 ngày 22 giờ
Pull request đã merge (30 ngày)
81

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của docker/compose

Tất cả issue của docker/compose

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.