Reputation: 685
Tried to search the Docker documentation, however, I cannot find anything that directly relates to a backup on the down
command. Additionally, I see you can add your own command
script in the yml on up
, so I was hoping that there might be something similar for down
?
Upvotes: 0
Views: 249
Reputation: 5557
You need to make your own entrypoint script that will create an exit hook. You can see more details on the steps of building custom image with a custom entrypoint in this SO.
In your case, the entrypoint will look like this:
#!/bin/bash
set -e
execute_on_finish() {
echo "Execute on finish"
}
trap execute_on_finish EXIT
echo "CALLING ENTRYPOINT WITH CMD: $@"
exec /old_entrypoint.sh "$@" &
daemon_pid=$!
wait $daemon_pid
execute_on_finish
Since the backup process is a long operation, and docker will execute a
kill
if the process doesn't shut-down in 10s, you will need to send option to thestop
not to kill the container with-t
. See more details here
Upvotes: 1