1

I'm setup a database container with a script rc.db which provide standard init commands like:

/etc/rc.db start
/etc/rc.db stop
/etc/rc.db status

In Is it possible to install a complex server inside a Docker container?, I know I could use a simple script to start the db container(for example name as /etc/db_run.sh:

#/bin/sh
/etc/rc.db start
wait

And the Dockerfile ... RUN /etc/db_run.sh

Because close database correctly is important. I wish when the container be stopped, it could call the /etc/rc.db stop.

Community
  • 1
  • 1
Daniel YC Lin
  • 15,050
  • 18
  • 63
  • 96

1 Answers1

0

When Docker tries to stop a container, it sends a SIGTERM signal, followed by a SIGKILL after a grace period. Just catch this signal and either call your script or pass it onto the DB process, whichever is appropriate.

I suspect that if you make the DB the main process running in the foreground, it will handle the signals correctly itself.

Adrian Mouat
  • 44,585
  • 16
  • 110
  • 102