logo

A quick fix for slow Docker container restarts

Compose may be waiting on a signal your dev server never handles

Joel Clermont
Joel Clermont
2026-09-10

After setting up Compose watch on a project, I noticed that every rebuild came with the same awkward pause. The new image was ready in a couple of seconds, but the old container took another ten seconds to go away before the new one started.

The pause has nothing to do with watch itself. When Compose stops a container, it sends the process a SIGTERM and waits for it to exit. If the process never responds, Compose gives up after a grace period and sends SIGKILL instead. That grace period defaults to ten seconds.

Dev servers started with npm run dev are a common way to hit this, since they often never handle that signal at all.

In this case, you can simply set a shorter grace period in your compose file:

# docker-compose.yml
services:
  frontend:
    build: .
    stop_grace_period: 1s

Now Compose only waits one second before killing the container, and rebuilds and restarts feel instant.

But it's important to be careful about when you use this approach. It's fine for a dev server that holds no state, but I would never put it on the database container, where a hard kill in the middle of a write could result in data loss or corruption.

And, to be totally honest, this initial solution I came up with is just a workaround ignoring the source of the problem. The real fix is getting the process to handle SIGTERM properly, and I explain how to do that in a separate tip.

Here to help,

Joel

P.S. Small Docker mysteries like this one are exactly what people bring to our community, and we work through them together.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice.