2024-03-19

Stop/Remove All Docker containers

This article contains few hints when you are using docker. My main article about is How Docker is disrupting Legacy IT Companies.

Contents

Stop/remove all Docker containers

Hints to use with docker.

In the version 1.13.x and higher :

Remove all unused containers, volumes, networks, and images (both dangling and unreferenced).

 system prune

Link: doc docker

Removes all stopped containers.

 container prune

Link: doc docker

Hack and hints

There are many ways to stop/remove all containers.

 On Unix/Linux :

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

One-liner:

 rm -f $( ps -a -q)

For All images :

docker rmi $(docker images -q)

Remove all containers and volumes :

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

Stop faster docker images :

docker ps -a -q | xargs -n 1 -P 8 -I {} docker stop {}

 Windows

FOR /f "tokens=*" %i IN ('docker ps -a -q') DO docker rm %i

Powershell

docker rm @(docker ps -aq)

Link :

Sylvain Leroy

Senior Software Quality Manager and Solution Architect in Switzerland, I have previously created my own company, Tocea, in Software Quality Assurance. Now I am offering my knowledge and services in a small IT Consulting company : Byoskill and a website www.byoskill.com Currently living in Lausanne (CH)

View all posts by Sylvain Leroy →