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:

  • Docker to run new container - list of all mapped ports?
  • Any conflicts using Docker Toolbox for Mac and Already-Installed Virtualbox?
  • Go shared libraries for Docker containers to share
  • Docker OSX disc storage
  • How to access to Google AppEngine Managed VM logs?
  • Smart Stack + Docker
  • 1. [On Dockerfile’s ENTRYPOINT] Use trap per the docs

    trap "echo TRAPed signal" HUP INT QUIT KILL TERM
    /usr/sbin/apachectl start

    2. [On Host] Use docker events

    Run docker events, filtering on die or shutdown (see docs) until I see my container’s hash. Then run my clean-up logic when such an event occurs (example: via bash script`)


    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.

  • docker-compose replica hostname
  • docker with ansible wait for database
  • Sending email using smtplib in ubuntu docker throws “421 4.3.2 Connection rate limit exceeded”
  • Google Container Registry pushing images into purgatory
  • Docker for traditional web application with load balancing?
  • How to maintain repositories into a single repository
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.