Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Daemon stop - Timeout for container defaults 10s

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.

like image 955
notes-jj Avatar asked May 02 '16 09:05

notes-jj


People also ask

How do you stop a docker container from stopping?

According to this answer, adding the -t flag will prevent the container from exiting when running in the background. You can then use docker exec -i -t <image> /bin/bash to get into a shell prompt.

How do I stop docker daemon from running?

Start the daemon manually You may need to use sudo , depending on your operating system configuration. When you start Docker this way, it runs in the foreground and sends its logs directly to your terminal. To stop Docker when you have started it manually, issue a Ctrl+C in your terminal.

Does docker stop wait?

Docker has limited patience when it comes to stopping containers. There's a timeout, which is 10 seconds by default for each container. If even one of your containers does not respond to SIGTERM signals, Docker will wait for 10 seconds at least.

Which command is used to stop docker container?

To stop one or more running Docker containers, you can use the docker stop command. The syntax is simple: $ docker stop [OPTIONS] CONTAINER [CONTAINER...] You can specify one or more containers to stop.


2 Answers

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
like image 86
lcgogo Avatar answered Oct 06 '22 08:10

lcgogo


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.

like image 1
Ken Cochrane Avatar answered Oct 06 '22 06:10

Ken Cochrane