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
@francolaiuppa

This comment has been minimized.

francolaiuppa commented May 8, 2016

hey I found your gist while doing a google search, thanks for sharing! I had the same problem and fixed it using some bash fu, maybe this will help?

docker kill $(docker ps -q)

@ktamas77

This comment has been minimized.

ktamas77 commented Jul 20, 2016

@francolaiuppa exactly, these are the best solutions:

stop all containers:
docker kill $(docker ps -q)

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

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

@arkka

This comment has been minimized.

arkka commented Aug 12, 2016

remove all docker volumes
docker volume ls -qf dangling=true | xargs -r docker volume rm

@coolavibv

This comment has been minimized.

coolavibv commented Feb 19, 2017

I recommend do not use "docker kill $(docker ps -q)" for stopping all containers because it's a brute force method. Instead you can use docker stop $(docker ps -a -q) which does it smoothly.

@johan-lejdung

This comment has been minimized.

johan-lejdung commented Feb 22, 2017

@coolavibv why would you type docker stop $(docker ps -a -q) instead of docker stop $(docker ps -q)?

Are you able to stop non-running containers any further than they already are?

@miked0004

This comment has been minimized.

miked0004 commented Apr 1, 2017

@timka

This comment has been minimized.

timka commented May 24, 2017

Here's how to clear everything unused: docker ps -q | xargs -r docker stop ; docker system purge -a

@orloc

This comment has been minimized.

orloc commented Sep 5, 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.

@luty81

This comment has been minimized.

luty81 commented Oct 9, 2017

Remove all containers by image:
docker rm (docker ps -a |grep [IMAGE_NAME] |awk '{print $1}')

Example: remove all redis containers:
docker rm (docker ps -a |grep redis |awk '{print $1}')

@blackbird014

This comment has been minimized.

blackbird014 commented Oct 15, 2017

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

@perlun

This comment has been minimized.

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

This comment has been minimized.

melnikaite commented Nov 30, 2017

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

@grosser

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

copremesis commented May 29, 2018

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

@vvkpd

This comment has been minimized.

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)

@aristotelesbr2014

This comment has been minimized.

aristotelesbr2014 commented Jun 15, 2018

@gdevdeiv This work for me!!! Tks!

@bitbd83

This comment has been minimized.

bitbd83 commented Aug 6, 2018

good- very helpful.

@pepinu

This comment has been minimized.

pepinu commented Aug 29, 2018

cool

@joel-hamill

This comment has been minimized.

joel-hamill commented Aug 30, 2018

@felipecrestani

This comment has been minimized.

felipecrestani commented Sep 4, 2018

Thanks @gdevdeiv...

@meteorplus

This comment has been minimized.

meteorplus commented Sep 13, 2018

docker dance $(docker ps -q)

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