[Docker] Remove all containers that are stopped

Created on November 30, 2026

Pipe the IDs from docker ps -aq into docker rm using xargs. This removes stopped containers. Docker refuses to remove running containers with this command, so stop them first if you intend to remove them as well.

sudo docker ps -aq | xargs sudo docker rm

-a includes both running and stopped containers, and -q prints only their IDs.

References

Docker