Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker command that purges everything

Tags:

docker

Is there a single docker command that can be used to purge everything? Stop all containers if running, delete all images, delete all volumes... ect.

like image 611
Sid Avatar asked Jun 14 '26 03:06

Sid


1 Answers

I don't think there is a single command to do that. You first need to stop all containers using

$ docker stop `docker ps -qa` > /dev/null 2>&1; ## Stop all running containers
$ docker system prune --volumes --all; ## Remove all unused docker components

Usage on prune can be found in docker official documentation.

You can still run the above 2 commands in a single line.

$ docker stop `docker ps -qa` > /dev/null 2>&1; docker system prune --volumes --all;

Or an alias should help

alias dockerRemoveAll="docker stop `docker ps -qa` > /dev/null 2>&1; docker system prune --volumes --all;"

Edit-1:
Based on @Zeitounator's comment, I've added > /dev/null 2>&1 to redirect whatever the output is to null and stderr. This still continues to remove all the docker contents even when the exit code is 1 for the stop command when there are no containers.

Also @Zeitounator's wipedocker function is even more elegant.

like image 188
vijay Avatar answered Jun 17 '26 01:06

vijay