Skip to content
Blog

Force-Stopping Containers and Understanding SIGKILL in Docker

A deep dive into force-stopping Docker containers using SIGKILL, signal propagation for PID 1, SIGTERM vs SIGKILL differences, and custom signals with docker kill --signal.

Published on • November 17, 2026

AI Assistant

When managing application containers in production or development environments, services may occasionally become unresponsive, freeze in deadlock, or ignore standard shutdown procedures. In these scenarios, graceful stopping via docker stop might time out, necessitating force-termination.

Docker provides docker kill to immediately halt execution by sending Linux kernel signals directly to the container’s primary process. Understanding how Linux signals interact with process namespaces, PID 1, and Docker runtime mechanics is essential for system administrators and DevOps engineers.


1. Graceful vs Immediate Termination: SIGTERM vs SIGKILL

To understand container termination, it is important to distinguish between Linux standard signals:

FeatureSIGTERM (Signal 15)SIGKILL (Signal 9)
PurposeGraceful termination requestImmediate, ungraceful kernel kill
Catchable / InterceptableYes (Process can catch, clean up, and exit)No (Handled directly by Linux kernel)
File / Buffer SafetyHigh (Flushes state, releases locks, closes sockets)Low (Risk of corrupted files or pending writes)
Command Sent Bydocker stop (initially)docker kill or docker stop timeout

When you run docker stop, Docker sends SIGTERM to PID 1, waits for a grace period (default 10 seconds), and sends SIGKILL if the container is still running. In contrast, docker kill bypasses the grace period and sends SIGKILL immediately by default.


2. Using docker kill to Force Stop Containers

To immediately terminate a running container without waiting for a timeout, use the docker kill command:

docker kill <container_name_or_id>

Example Usage:

# Run a background container running a infinite loop
docker run -d --name unresponsive-app alpine sh -c "while true; do sleep 1; done"

# Immediately force-stop the container
docker kill unresponsive-app

Upon execution, the Linux kernel immediately destroys the main process thread group inside the container’s PID namespace. The container transitions to an Exited state with exit code 137 (128 + signal 9).


3. Custom Signals with --signal

While docker kill defaults to sending SIGKILL, the --signal (or -s) flag allows you to dispatch any valid POSIX signal to PID 1 inside the container.

Common Signal Examples:

# Send SIGINT (equivalent to Ctrl+C)
docker kill --signal=SIGINT my-web-app

# Send SIGHUP to trigger configuration reload in servers like NGINX
docker kill --signal=SIGHUP nginx-proxy

# Send SIGUSR1 for application-defined diagnostic dumps
docker kill --signal=SIGUSR1 nodejs-api

This flexibility makes docker kill a powerful tool for triggering maintenance tasks or state dumps without stopping the container entirely.


4. Signal Forwarding and the PID 1 Problem

In Linux, process ID 1 (PID 1) has a special role inside a container’s PID namespace. Unlike standard processes, kernel rules specify that PID 1 will ignore default signal handlers unless an explicit signal handler is registered in code.

The Shell vs Exec Form Trap

If your Dockerfile starts an application using the shell form of ENTRYPOINT or CMD:

# Shell form: executes /bin/sh -c "node index.js"
CMD node index.js

Inside the container, /bin/sh runs as PID 1, and your Node.js application runs as a child process. Standard shells do not forward signals like SIGTERM or SIGKILL to child processes automatically.

The Solution: Exec Form and Tini

Always use the exec form in Dockerfiles so your application runs directly as PID 1:

# Exec form: runs node directly as PID 1
CMD ["node", "index.js"]

Alternatively, use an init process manager like tini (docker run --init ...) to properly reap zombie processes and forward POSIX signals to all child processes.


5. Summary and Best Practices

Takeaway: docker kill sends an immediate SIGKILL (Signal 9) to container processes by default, causing immediate kernel-level termination without process cleanup. Use docker stop for standard application shutdowns, reserve docker kill for stuck processes or custom signal routing via --signal, and ensure your container entrypoints run via exec syntax or --init for proper signal handling.


Sources