I am unable to run my service pre_stop hook. The YAML
services:
hooks-test:
image: alpine
command: /bin/sh -c "echo this is command; sleep 3600”
post_start:
- command: /bin/sh -c "echo this is post_start”
pre_stop:
- command: /bin/sh -c "echo this is pre_stop”
does not produce the pre_stop output, when stopped by any of: Ctrl+C
, compose down, or compose stop.
Steps to reproduce:
$ docker compose -f hooks.yaml up
[+] Running 1/1
✔ Container container-hooks-test-1 Created 0.0s
Attaching to hooks-test-1
hooks-test-1 | this is command
hooks-test-1 -> | this is post_start
(Ctrl+C)
Gracefully stopping... (press Ctrl+C again to force)
[+] Stopping 1/1
✔ Container container-hooks-test-1 Stopped 10.3s
My config:
- OS: MacOs Sonoma 14.7.1
- Docker Compose version v2.33.1-desktop.1
How do I get the pre_stop hook to run?