Skip to content

Instantly share code, notes, and snippets.

@nickcernis
Last active August 5, 2024 12:34
Show Gist options
  • Save nickcernis/81b7b6498da559436c5172f0ccae760c to your computer and use it in GitHub Desktop.
Save nickcernis/81b7b6498da559436c5172f0ccae760c to your computer and use it in GitHub Desktop.
Docker commands to remove all containers and images

docker kill $(docker ps -q) to kill all running containers
docker rm $(docker ps -a -q) to delete all stopped containers.
docker volume rm $(docker volume ls -q) to delete all volumes.
docker rmi $(docker images -q) to delete all images.

Run all commands:

docker kill $(docker ps -q) && docker rm $(docker ps -a -q) && docker volume rm $(docker volume ls -q) && docker rmi $(docker images -q)

For fish shell, remove the $:

docker kill (docker ps -q) to kill all running containers
docker rm (docker ps -a -q) to delete all stopped containers.
docker volume rm (docker volume ls -q) to delete all volumes.
docker rmi (docker images -q) to delete all images.

Run all commands:

docker kill (docker ps -q) && docker rm (docker ps -a -q) && docker volume rm (docker volume ls -q) && docker rmi (docker images -q)

If you see “[command name] requires at least 1 argument”, there were no containers or images to stop or remove.

@eldaroid
Copy link

eldaroid commented May 1, 2024

By default, the system prune command does not delete volumes to prevent important data from being deleted if there is currently no container using the volume. Use this --volumes flag when running the command to also delete volumes docker system prune -af --volumes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment