Deleting all docker images and containers

To remove all containers,

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

-v: Remove all associated volumes

-f: Forces the removal. Like, if any containers is running, you need -f to remove them.

To remove all images,

docker rmi -f $(docker images -a -q)

-a: for all containers, even not running, (or images)

-q: to remove all the details other than the ID of containers (or images)


to delete all containers:

docker rm $(docker ps -a -q)

to delete all images:

docker rmi $(docker images -q)

Note that you can't revert and you can't kill containers which running, you should stop them before


See all the existing images:

docker images -a

See all the existing containers:

docker ps -a

Delete single image:

docker images -a
docker rmi <IMAGE_ID>

Delete single container:

docker ps -a
docker rm <CONTAINER_ID>

Delete multiple images:

docker images -a
docker rmi <IMAGE_ID1> <IMAGE_ID2>

Delete multiple containers:

docker ps -a
docker rm <CONTAINER_ID1> <CONTAINER_ID2>

Stop all containers and remove them:

docker rm $(docker kill $(docker ps -aq))

Delete all images:

docker rmi -f $(docker images -a -q)

Delete both all stopped containers and images in a single command:

docker rm $(docker ps -a -q) && docker rmi -f $(docker images -a -q)

To prune all containers:

docker container prune

Delete all unused data (i.e., in order: containers stopped, volumes without containers and images with no containers):

docker system prune

This is the command to be used for your question. It deletes everything(container , images, cache, etc..)

docker system prune

Warning

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all dangling build cache
Are you sure you want to continue? [y/N] n

Tags:

Docker