Skip to main content
← Gists
bash Dec 10, 2025

Kill All Running Docker Containers

Stop every running container in one shot with docker kill and xargs.

Terminate every running Docker container in a single command. I reach for this when my local environment is cluttered with leftover containers from previous experiments and I need a clean slate before spinning up a fresh stack.

The command

kill-all-containers.sh
# Kill all running Docker containers, by sending
# them a SIGKILL signal.
docker ps -q \
  | xargs docker kill

How it works

  • docker ps -q lists the IDs of all running containers. The -q (quiet) flag strips away headers, names, and status columns, returning one container ID per line. Just the handles, nothing else.
  • | pipes those IDs into xargs, which builds and executes the docker kill command with each ID as an argument. When stdin is empty (no running containers), xargs skips execution entirely, so the command becomes a silent no-op.
  • docker kill sends SIGKILL to each container ID it receives. Immediate termination, no graceful shutdown, no waiting for cleanup handlers. Containers stop on the spot.

When to use this

  • Clearing a messy local environment — after a day of spinning up containers for different projects, kill them all and reclaim resources.
  • Resetting before integration tests — test suites that depend on specific container state run more reliably from a blank slate.
  • Quick post-experiment cleanup — tried three different Redis configurations? Kill them all, start the one you actually need.

Further reading

  • docker kill reference — full docs on signals, options, and behavior with shell-form ENTRYPOINT
  • docker ps reference — all filtering flags, format options, and the difference between -q, -a, and --filter