Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
kill all docker containers at once...
docker ps | awk {' print $1 '} | tail -n+2 > tmp.txt; for line in $(cat tmp.txt); do docker kill $line; done; rm tmp.txt
@blackbird014
Copy link

blackbird014 commented Oct 15, 2017

in Cmder
@for /f "tokens=*" %i IN ('docker container ls -aq') DO docker container rm %i

@perlun
Copy link

perlun commented Nov 20, 2017

docker system prune

https://docs.docker.com/engine/reference/commandline/system_prune/

This is the preferred way. Removes all volumes / images / networks and everything else.

Note: only not running containers. So you might want to shut all containers down first.

@melnikaite
Copy link

melnikaite commented Nov 30, 2017

docker rm -f $(docker ps -f name=IMAGE_NAME -q) || true

@grosser
Copy link

grosser commented Jan 3, 2018

  • rm -f stops and removes the containers
  • when nothing is running the rm fails

so using this:
docker rm -f $(docker ps -aq) >/dev/null 2>&1 || true

@gdevdeiv
Copy link

gdevdeiv commented May 20, 2018

On macOS this is my way to go (adapted from @timka):

docker ps -q | xargs docker stop ; docker system prune -a

@copremesis
Copy link

copremesis commented May 29, 2018

@coolavibv that was smooth ... dang github needs a tangent thread like reddit now .. cheers

@vvkpd
Copy link

vvkpd commented Jun 11, 2018

remove all containers forcefully
docker rm -f $(docker ps -a -q)

remove all docker images forcefully
docker rmi -f $(docker images -q)

@aristotelesbr
Copy link

aristotelesbr commented Jun 15, 2018

@gdevdeiv This work for me!!! Tks!

@bitbd83
Copy link

bitbd83 commented Aug 6, 2018

good- very helpful.

@pepinu
Copy link

pepinu commented Aug 29, 2018

cool

@joel-hamill
Copy link

joel-hamill commented Aug 30, 2018

@felipecrestani
Copy link

felipecrestani commented Sep 4, 2018

Thanks @gdevdeiv...

@x5engine
Copy link

x5engine commented Sep 13, 2018

docker dance $(docker ps -q)

@andrasnagyad
Copy link

andrasnagyad commented Mar 19, 2019

#stop all containers:
docker stop $(docker ps -a -q)

#stop all containers by force
docker kill $(docker ps -q)

#remove all containers
docker rm $(docker ps -a -q)

#remove all docker images
docker rmi $(docker images -q)

#purge the rest
docker system prune --all --force --volumes

@yangtopia
Copy link

yangtopia commented Jul 22, 2019

Thanks!

@oueryemchi
Copy link

oueryemchi commented Aug 6, 2019

docker kill [ID]

To get the ID of the running container, run:
docker ps

example:

docker kill b0e6f105b024

@da7a90
Copy link

da7a90 commented Sep 25, 2019

@francolaiuppa lol bash fu

@labohkip81
Copy link

labohkip81 commented Nov 15, 2019

Thanks, helped.

@AndersonChoi
Copy link

AndersonChoi commented Nov 25, 2019

Thank you all

@eenchev
Copy link

eenchev commented Dec 4, 2019

@evanscottgray that's a terrible way to do it. As others have pointed out, do not do this, but:
docker kill $(docker ps -q)

@IOnlyFetchBranches
Copy link

IOnlyFetchBranches commented Dec 12, 2019

why is there not simply a docker container stop --all or something similar for windows? Sorry if this question has already been answered

@ddelrio1986
Copy link

ddelrio1986 commented Dec 14, 2019

If you want to be a hipster and stop all running containers using the management commands than use this.

docker container stop $(docker container ls -q)

@adeelibr
Copy link

adeelibr commented Feb 17, 2020

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

@evanscottgray
Copy link
Author

evanscottgray commented May 9, 2020

@eenchev completely agree. When I wrote this like six years ago, I had no idea what I was doing. 😅

...and some would argue that not much has changed!

These days I use something closer to docker ps -qa | xargs docker stop.

@umar-muneer
Copy link

umar-muneer commented Sep 23, 2020

docker container stop $(docker container ls -q)

thanks, worked like a charm !!

@veritem
Copy link

veritem commented Dec 3, 2020

All didn't work for me

I used docker stop $(docker ps -a -q)

@chrisharrisonkiwi
Copy link

chrisharrisonkiwi commented Dec 11, 2020

All did n't work for me

I used docker stop $(docker ps -a -q)

docker kill, not stop

@digitalist
Copy link

digitalist commented Mar 26, 2021

@webdev23
Copy link

webdev23 commented May 16, 2021

sudo docker kill $(sudo docker ps -q)

@sorenwacker
Copy link

sorenwacker commented May 22, 2021

Why not something like docker stopall ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment