Sometimes it's necessary to stop and remove all docker containers, images and free up some spaces. Here are few commands that might become handy to clean up your system.

Removing All Unused Docker Objects

  • Remove all stopped containers
  • Remove all networks not used by at least one container
  • Remove all dangling images
  • Remove all build cache
docker system prune

List, stop and remove docker containers

List containers

docker ps -a

List container IDs only

docker ps -aq

Stop a running container

docker stop bcce00bf8bac

Stop all running containers

docker stop $(docker ps -aq)

Removing one container

docker rm 24a4812a1778

Removing all stopped containers

docker rm $(docker ps -aq)

List, stop and remove docker images

List all images

 docker images

Removing one image

docker rmi image_id

Removing unused images

docker image prune

Remove all images

docker rmi $(docker images -q)

List and remove docker networks

List networks

docker network ls

Remove one network

docker network rm 014a46b60a9d

Removing all unused network

docker network prune

List and remove docker volumes

List volumes

docker volume ls

Remove on volume

docker volume rm 014a46b60a9d

Removing all unused volumes

docker volume prune