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).

1
docker system prune

Link : doc docker

Removes all stopped containers.

1
docker container prune

Link : doc docker

Hack and hints

There are many ways to stop/remove all Docker containers.

On Unix/Linux :

1
2
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

One-liner:

1
docker rm -f $(docker ps -a -q)

For All images :

1
docker rmi $(docker images -q)

Remove all containers and volumes :

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

Stop faster docker images :

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

Windows

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

Powershell

1
docker rm @(docker ps -aq)

Link :