13

docker stop has a standard timeout of 10s (Reference - Docker Stop). This time window may be to short for the shutdown of mysql or influxdb to reach a consistent state on file system. If I stopped the container by hand, I would shut it down with docker stop -t 60 mysql. But that is not the default case. The containers are on auto restart and started and stopped with the docker daemon.

If I stop the docker daemon (e.g. on system reboot), the daemon will stop all running container with a timeout of 10 seconds, which can cause inconsistent dbs.

Question: Is there a way to set the global timeout for docker stop or the daemon stop?

Update 2016-05-03: Added [Feature Request] Add config parameter to change stop timeout for containers or globally #22471 on github.

notes-jj
  • 1,437
  • 1
  • 20
  • 33

2 Answers2

10

https://docs.docker.com/engine/reference/commandline/dockerd/

Use the following config

--shutdown-timeout int            Set the default shutdown timeout (default 15)

or put it in docker daemon.json like below and restart docker daemon

tee /etc/docker/daemon.json <<-'EOF'
{
  "shutdown-timeout": 30,
  "live-restore": true
}
EOF
systemctl restart docker
systemctl status docker
lcgogo
  • 95
  • 1
  • 5
  • 1
    This is not woking. "live-restore" option makes docker terminate without containers termination - that causes container kill just after daemon termination on host shutdown. Just "shutdown-timeout" is not working as expected - there is issue for that: https://github.com/moby/moby/issues/32357 – Skipor Oct 30 '20 at 07:34
1

I'm pretty sure there isn't a global setting for this. It would be a nice feature, and you should submit an issue to suggest it, and if you have time submit a pull request to implement.

Ken Cochrane
  • 75,357
  • 9
  • 52
  • 60