Deleting Docker Entities

Sumeet Gyanchandani
1 min readJul 12, 2020

--

Source: https://www.docker.com/company/newsroom/media-resources

Purging all unused or dangling Images, Containers, Volumes, and Networks

  1. Introduction
  2. Docker File
  3. Basic Docker Commands
  4. Port and Volume Mapping
  5. Docker Networking
  6. Docker Storage
  7. Docker Compose
  8. Deleting Docker Entities (You are here!)

Docker provides a single command that will clean up any resources that are dangling (not associated with a container):

docker system prune

To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:

docker system prune -a

Remove all the images

docker rmi $(docker images -a -q)

Remove all exited containers

docker rm $(docker ps -a -f status=exited -q)

Stop and remove all the containers

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Reference:

[1] Melissa Anderson, How To Remove Docker Images, Containers, and Volumes (2017), digitalocean.com

--

--

Sumeet Gyanchandani

Associate Director at UBS | Former Machine Learning Engineer at Apple, Microsoft Research, Nomoko, Credit Suisse | Master of Science in Artificial Intelligence