Dumping DB before stopping the containers

I’m working with two different PCs in the same project. So sometimes I can commit a change from one PC and another time I can commit a change from another PC. In case the changes are involving the code, it’s not really a problem thanks to git; but what about the database?

The project uses docker (docker-compose) to spin up several services, among them I have a MySQL server. What I’d like to do, is dumping the latest version of the DB before the command docker-composer stop complete all the actions.

Is there a way I can inject the mysqldump [...] command when the docker-composer stop is running?

Any alternatives, just in case?

You can write an entrypoint script that catches the interruption signal and dumps your data before exiting. Or just do a docker-compose run db mysqldump ... as part of your git hooks?

Great! I’m quite new on this kind of things with Docker… Any guide/documentation I can refer to for creating an entrypoint and catch signals?

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_12_02.html#sect_12_02_03 provides a high level example of using a bash script.