Run Clean-up Logic on Docker Container's Shutdown/Killing?
- Host machine
- Docker container running web service
I’d like to implement “clean-up” logic upon the shutdown of the web service. It seems to me that there’s 2 ways to do this:
1. [On Dockerfile’s
trap per the docs
trap "echo TRAPed signal" HUP INT QUIT KILL TERM /usr/sbin/apachectl start
2. [On Host] Use
docker events …
docker events, filtering on
shutdown (see docs) until I see my container’s hash. Then run my clean-up logic when such an event occurs (example: via
I know little about Linux’s
SIGNAL‘s, as well as how processes handle such SIGNALs. So, I’m not sure if it’s possible in some scenarios for the clean-up logic to not be called.
In short, I’m curious of the best way to ensure that my clean-up script runs upon the shutdown/killing of a docker container.