Docker stop gracetime

Hi,

The application we’re running requires a stop grace time of 30 seconds. (The time between receiving SIGTERM and SIGKILL).

They are simply started using docker run …

It works fine when we shut them down manually using : docker stop master-app -t 30

However, when the host is shutdown by doing systemctl stop docker, the containers are not shut down gracefully.

We’ve tried changing this in the daemon settings but it does not do what we need.

cat /etc/docker/daemon.json <<-‘EOF’
{
“shutdown-timeout”: 30
}

Is there something we could do to make systemctl stop docker wait longer before killing containers ?

Regards,

burni

1 Like

This might shed some light on the situation: dockerd shutdown-timeout option does not work as expected · Issue #32357 · moby/moby · GitHub

TL;DR: start your container with docker run --stop-timeout 30 ... and it should work as required.

1 Like

Thank you very much! That did the trick!

I’m arriving at this issue in 2025 since I only just realized that the docker daemon is killing containers if they don’t exit in (to me, at least) a very short time period. I’m surprised I haven’t noticed any data corruption yet, since I have several containers that run databases or store persistent data in other ways and which seemingly aren’t being given adequate time to shutdown. The linked GitHub issue is still open, as well. I’m also realizing that the global shutdown-timeout option doesn’t seem to have affect for some of my containers. Is the only current solution to specify the stop-timeout on a container-by-container basis?