When Docker is running on a system under high load, it may fail to stop all processes properly during shutdown.
To mitigate this issue, you can optimize the shutdown-timeout parameter for the Docker daemon.
The shutdown-timeout parameter specifies the number of seconds Docker will wait for containers to stop before forcefully terminating them during a shutdown or restart.
To test and optimize this setting for your system:
-
Locate the Docker daemon configuration file, typically found at
/etc/docker/daemon.json. -
Open the file and add or update the
shutdown-timeoutparameter. For example:
{
"shutdown-timeout": 15
}
In this example, Docker will wait 15 seconds for containers to stop before forcefully terminating them.
- Save the file and restart the Docker daemon for the changes to take effect.
sudo systemctl restart docker
- Test the new
shutdown-timeoutvalue by performing a system shutdown or Docker restart, and observe the behavior. Adjust the value as needed, based on the time required for your containers to stop gracefully.
By optimizing the shutdown-timeout parameter, you can ensure that Docker has sufficient time to properly stop all running containers, even under high system load conditions.