Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove all from Docker
# Stop all containers
docker stop `docker ps -qa`
# Remove all containers
docker rm `docker ps -qa`
# Remove all images
docker rmi -f `docker images -qa `
# Remove all volumes
docker volume rm $(docker volume ls -qf)
# Remove all networks
docker network rm `docker network ls -q`
# Your installation should now be all fresh and clean.
# The following commands should not output any items:
# docker ps -a
# docker images -a
# docker volume ls
# The following command show only show the default networks:
# docker network ls
@AvgustPol

This comment has been minimized.

Copy link

@AvgustPol AvgustPol commented Nov 8, 2018

<3

@MeharGaur

This comment has been minimized.

Copy link

@MeharGaur MeharGaur commented Dec 9, 2018

this is awesome lol

@catruck

This comment has been minimized.

Copy link

@catruck catruck commented Jan 23, 2019

nice

@samhk222

This comment has been minimized.

Copy link

@samhk222 samhk222 commented Feb 26, 2019

the "f" parameter in docker volume rm $(docker volume ls -qf) is for filter. if you don't specify it, it'll raise an error. But it's safe to ommit the f parameter, or here is the list of available filters:

  • dangling (boolean - true or false, 0 or 1)
  • driver (a volume driver’s name)
  • label (label= or label==)
  • name (a volume’s name)

Example:
docker volume rm $(docker volume ls -qf dangling="true")

@AymAZR

This comment has been minimized.

Copy link

@AymAZR AymAZR commented Mar 26, 2019

@samhk222 docker volume rm $(docker volume ls -qf dangling="true") works perfectly! Thanks a lot!

@KonradLinkowski

This comment has been minimized.

Copy link

@KonradLinkowski KonradLinkowski commented May 20, 2020

Oneliner

docker stop `docker ps -qa` && docker rm `docker ps -qa` && docker rmi -f `docker images -qa ` && docker volume rm $(docker volume ls -qf) && docker network rm `docker network ls -q`
@acjohnson

This comment has been minimized.

Copy link

@acjohnson acjohnson commented Jul 2, 2020

Better and more destructive oneliner

docker stop $(docker ps -qa); docker rm $(docker ps -qa); docker rmi -f $(docker images -qa); docker volume rm $(docker volume ls -q); docker network rm $(docker network ls -q)
@minhlong

This comment has been minimized.

Copy link

@minhlong minhlong commented Jul 11, 2020

<3 you save me. Thank you

@nash403

This comment has been minimized.

Copy link

@nash403 nash403 commented Sep 25, 2020

thnx !! 😃

@Maxzor

This comment has been minimized.

Copy link

@Maxzor Maxzor commented Sep 28, 2020

Shell scripts are damn ugly. But shell is so powerful 🙃
Why is rm -rf --all not in the docker binary lol...
Sigh, another try which does the same, but outputs less noise and adds a bit of sugar :

echo "Removing containers :" && if [ -n "$(docker container ls -aq)" ]; then docker container stop $(docker container ls -aq); docker container rm $(docker container ls -aq); fi; echo "Removing images :" && if [ -n "$(docker images -aq)" ]; then docker rmi -f $(docker images -aq); fi; echo "Removing volumes :" && if [ -n "$(docker volume ls -q)" ]; then docker volume rm $(docker volume ls -q); fi; echo "Removing networks :" && if [ -n "$(docker network ls | awk '{print $1" "$2}' | grep -v 'ID\|bridge\|host\|none' | awk '{print $1}')" ]; then docker network rm $(docker network ls | awk '{print $1" "$2}' | grep -v 'ID\|bridge\|host\|none' | awk '{print $1}'); fi;

Readable bash script at https://gist.github.com/Maxzor/6a3ca2c5c1c28af583711abc8e5fda01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.