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

Offen
#14,476 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@htoyoda18 arbeitet bereits daran.

Seit 07.11.2026.

  • #14477 von @htoyoda18 — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
53/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
docker-compose, go
Bereich
devops

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
Go
Sterne
38.9k
Forks
6k
Ø Merge
2 T. 22 Std.
Gemergte PRs (30 T.)
81

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus docker/compose

Alle Issues in docker/compose

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.