Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting all docker images and containers

Tags:

docker

I am very new to Docker and enjoying it very much.

I want to delete all images and containers from local as well as from docker hub. Is there any single command to do that?

like image 557
Adil Malik Avatar asked Jun 27 '16 17:06

Adil Malik


People also ask

How do I delete all docker images and containers?

Remove all Containers: To remove all containers from the docker-machine, we need to get the ids of all the containers. We can simply get the ids of the containers with the command docker ps -aq, then by using the docker rm command, we can remove all the containers in the docker-machine.

How do I clean up docker images and containers?

To clean this up, you can use the docker container prune command. By default, you are prompted to continue. To bypass the prompt, use the -f or --force flag. Other filtering expressions are available.

How do I remove all containers?

Stop and remove all containers The command docker container ls -aq generates a list of all containers. Once all containers are stopped, remove them using the docker container rm command, followed by the containers ID list.


2 Answers

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)

like image 135
gibumba Avatar answered Sep 28 '22 10:09

gibumba


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 
like image 34
Thavaprakash Swaminathan Avatar answered Sep 28 '22 08:09

Thavaprakash Swaminathan