How to remove all docker containers

I want to delete all my docker containers at once. I tried using $ docker rm [container_id] to do this, but it only deleted one container, not all.

Is there a way to remove all docker containers using a single line of code?

+6
source share
8 answers

Remove containers based on state:

docker rm -v $(docker ps --filter status=exited -q) 

Note:

  • The -v option, which will delete all volumes associated with the containers.

Empty all containers on my development machine:

 docker rm -v -f $(docker ps -qa) 

Note:

  • The option "-f" will force to delete the running container
+4
source
 docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q) 
+2
source

on ubuntu

 sudo docker ps -qa | xargs -n1 sudo docker rm 
+2
source

For Windows:

 C:\> for /F %i in ('docker ps -qa') do docker rm %i 
+1
source

For Windows (PowerShell):

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

I do this using the bash script loop and the docker rm command:

 $ for id in $(docker ps -aq); do docker rm $id; done 
0
source

Kill active containers: for /F %i in ('docker ps') do docker kill %i

Delete passive containers: for /F %i in ('docker ps -qa') do docker rm %i

Powered by Docker 17.xx

0
source

Like from Docker 1.13.0 --- Docker API 1.25 :

 docker container prune 

Output:

 WARNING! This will remove all stopped containers. Are you sure you want to continue? [y/N] y Deleted Containers: df226cc24539833a1c88f46bfa382ebe2e89c21805288f5e6bfc37cb7f662505 993bd58faaa22cb5dbc263eca33c8d1a241bd0a1f73b082e23e3a249fe1dfc0d ... Total reclaimed space: 13.88MB 

Read more about remove docker basket

There is a matrix of docker versions for a better understanding of docker versions (current Docker 17.12 --- Docker API 1.35 )

0
source

All Articles