Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … Container takes 10 seconds to stop (exit code 137)

Why a container takes 10 seconds to stop: PID 1 and SIGTERM

The app never receives SIGTERM, so Docker waits 10 seconds and kills it.

Docker

What it means

docker stop sends SIGTERM to PID 1, waits (10 s by default), then sends SIGKILL (exit 137). If PID 1 is a shell running your app, the shell doesn't forward the signal, and PID 1 also ignores signals it has no handler for.

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. Shell-form CMD or an entrypoint script that doesn't exec the app

Check:

docker exec <c> ps -o pid,args   # PID 1 is sh -c ...

Fix: Use exec-form CMD ["app"] and end entrypoint scripts with exec "$@".

2. The app has no SIGTERM handler

Check:

time docker stop <c>

Fix: Handle SIGTERM (finish requests, close connections), or run with --init (tini) as PID 1.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors