title: trapping signal from "docker stop" in bash
body: <p>i have an entry point script in a docker container that looks something like the following:</p>
  
  <pre><code>#!/bin/bash
  
  echo starting up
  
  function shut_down() {
      echo shutting down
  
      pid=$(ps -e | grep myapp | awk '{print $1}')
      kill -SIGTERM $pid  
      exit
  }
  
  trap "shut_down" SIGKILL SIGTERM SIGHUP SIGINT EXIT
  
  /opt/myapp
  </code></pre>
  
  <p>I can't figure out how to trap the signal sent in by running <code>docker stop</code> on the container. When running interactively, a <code>ctrl+c</code> will trigger it as expected, but a <code>docker stop</code> command just waits for the 10 second timeout, and exits without ever entering the <code>shut_down</code> function</p>
  
  <p>How can I trap the signal sent by <code>docker stop</code> in bash to do some cleanup?</p>