Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
delete all docker container and images on windows
@echo off
FOR /f "tokens=*" %%i IN ('docker ps -aq') DO docker rm %%i
FOR /f "tokens=*" %%i IN ('docker images --format "{{.ID}}"') DO docker rmi %%i
@TopSwagCode

This comment has been minimized.

Copy link

@TopSwagCode TopSwagCode commented Aug 21, 2017

thx 👍 Saved me some time of removing alot of crap.

@yakovenkoroman1993

This comment has been minimized.

Copy link

@yakovenkoroman1993 yakovenkoroman1993 commented Nov 7, 2017

Thanks!

@bluesman80

This comment has been minimized.

Copy link

@bluesman80 bluesman80 commented Nov 30, 2017

Thank you!

@omerbn

This comment has been minimized.

Copy link

@omerbn omerbn commented Dec 24, 2017

THANK YOU

@jeonguk

This comment has been minimized.

Copy link

@jeonguk jeonguk commented Dec 28, 2017

Thank you!

@kmbuco

This comment has been minimized.

Copy link

@kmbuco kmbuco commented Jan 15, 2018

Thank you

@sdcb

This comment has been minimized.

Copy link

@sdcb sdcb commented Jan 26, 2018

Thank you!

@kingsj0405

This comment has been minimized.

Copy link

@kingsj0405 kingsj0405 commented Jan 26, 2018

👍

@GreggSetzer

This comment has been minimized.

Copy link

@GreggSetzer GreggSetzer commented Jan 30, 2018

I added docker stop command since I frequently forget to run docker stop $(ps -a -q). Thanks for the gist!

@echo off
FOR /f "tokens=*" %%i IN ('docker ps -aq') DO docker stop %%i && docker rm %%i
FOR /f "tokens=*" %%i IN ('docker images --format "{{.ID}}"') DO docker rmi %%i
@matsskoglund

This comment has been minimized.

Copy link

@matsskoglund matsskoglund commented Jan 31, 2018

Thanks!

@jaywryan

This comment has been minimized.

Copy link

@jaywryan jaywryan commented Feb 2, 2018

PowerShell is so much easier!

docker ps -aq | foreach {docker rm $_}
@Samshal

This comment has been minimized.

Copy link

@Samshal Samshal commented Feb 5, 2018

And Powershell can be so much faster @jaywryan

docker rm $(docker ps -aq)
@MuhammadBilalYar

This comment has been minimized.

Copy link

@MuhammadBilalYar MuhammadBilalYar commented May 19, 2018

@Samshal this command isn't working, giving me this error
"docker rmi" requires at least 1 argument.
See 'docker rmi --help'.

Usage: docker rmi [OPTIONS] IMAGE [IMAGE...] [flags]

Remove one or more images

@stiv-yakovenko

This comment has been minimized.

Copy link

@stiv-yakovenko stiv-yakovenko commented Jun 18, 2018

This doesn't work on Windows 10:
%%i was unexpected at this time.

@huysentruitw

This comment has been minimized.

Copy link

@huysentruitw huysentruitw commented Jul 5, 2018

@stiv-yakovenko when running those commands outside of a batch-file, you should replace %%i with %i.

@aedm

This comment has been minimized.

Copy link

@aedm aedm commented Jul 23, 2018

docker system purge -af
Works the same on Windows and Linux, removes all unused images, containers, and networks.

@gdansou

This comment has been minimized.

Copy link

@gdansou gdansou commented Aug 10, 2018

thanks !

@productiveAnalytics

This comment has been minimized.

Copy link

@productiveAnalytics productiveAnalytics commented Sep 5, 2018

docker system prune -af (for Windows 10)

@minhlong

This comment has been minimized.

Copy link

@minhlong minhlong commented Sep 20, 2018

Thanks so much!

@omerasif57

This comment has been minimized.

Copy link

@omerasif57 omerasif57 commented Dec 8, 2018

should be in the docs.

@yedincisenol

This comment has been minimized.

Copy link

@yedincisenol yedincisenol commented Dec 24, 2018

Thanks!

@mmgil

This comment has been minimized.

Copy link

@mmgil mmgil commented Jan 12, 2019

I Would like contribute with a version in PowerShell:

foreach ($line in $(docker ps -a) ) {

    $line -match "^\w{12}"
    $container = docker inspect $Matches.Values | ConvertFrom-Json

    if ( $container.id ) {
        docker rm $Matches.Values
    }
}
@trevore23

This comment has been minimized.

Copy link

@trevore23 trevore23 commented May 11, 2019

Thank you!

@jcarloslr10

This comment has been minimized.

Copy link

@jcarloslr10 jcarloslr10 commented May 28, 2019

Thx!!!

@mastroiannim

This comment has been minimized.

Copy link

@mastroiannim mastroiannim commented May 30, 2019

Powershell delete images
docker images -aq | foreach {docker rmi $_}

@dana-c0914

This comment has been minimized.

Copy link

@dana-c0914 dana-c0914 commented Jun 20, 2019

Thanks!

@alonstar

This comment has been minimized.

Copy link

@alonstar alonstar commented Jun 27, 2019

thank!

@dzek69

This comment has been minimized.

Copy link

@dzek69 dzek69 commented Jul 12, 2019

Thanks

@robece

This comment has been minimized.

Copy link

@robece robece commented Aug 23, 2019

docker images -aq | foreach {docker rmi -f $_}
Based on @mastroiannim suggestion, I added -f parameter to force image deletion

@egres82

This comment has been minimized.

Copy link

@egres82 egres82 commented Sep 21, 2019

Thank you!!!

@HenryBol

This comment has been minimized.

Copy link

@HenryBol HenryBol commented Oct 17, 2019

Super, thanks!!

@ppalni

This comment has been minimized.

Copy link

@ppalni ppalni commented Dec 2, 2019

This is pure GOLD. I and the rest of the world :) - THANK YOU !!!!!

@katlimruiz

This comment has been minimized.

Copy link

@katlimruiz katlimruiz commented Jan 31, 2020

docker system prune

worked now

@wodsonluiz

This comment has been minimized.

Copy link

@wodsonluiz wodsonluiz commented Feb 10, 2020

Thanks!

@pistocop

This comment has been minimized.

Copy link

@pistocop pistocop commented Apr 16, 2020

Thanks!

@mohammedalsayegh

This comment has been minimized.

Copy link

@mohammedalsayegh mohammedalsayegh commented May 3, 2020

Thanks!

@sawich

This comment has been minimized.

Copy link

@sawich sawich commented Sep 3, 2020

Thanks!

@AndreiMireichyk

This comment has been minimized.

Copy link

@AndreiMireichyk AndreiMireichyk commented Sep 18, 2020

Thanks!

@R0Wi

This comment has been minimized.

Copy link

@R0Wi R0Wi commented Sep 23, 2020

Thank you :-)

@ilanl

This comment has been minimized.

Copy link

@ilanl ilanl commented Nov 3, 2020

Saved me lot of headaches !

@pmutua

This comment has been minimized.

Copy link

@pmutua pmutua commented Nov 19, 2020

docker rm $(docker ps -aq)

Doesn't work here was the result

C:\Users\Administrator>docker rm $(docker ps -aq)
unknown shorthand flag: 'a' in -aq)
See 'docker rm --help'.
@carehart

This comment has been minimized.

Copy link

@carehart carehart commented Feb 26, 2021

pmutua, that doesn't work because it's only valid on Linux or from powershell. You're trying to run it from the Windows command line.

But here are two ways to get it to work:

  • you can literally run that command by passing it TO powershell on the DOS cmd line: powershell "docker rm $(docker ps -aq)"
  • or if running powershell at the cmd line strikes anyone as odd, we can do a variant of the longer command originally offered at the top of this gist, but we don't need to do it in a batch file. This would work: FOR /F %k in ('docker ps -aq') DO docker rm %k
@pmutua

This comment has been minimized.

Copy link

@pmutua pmutua commented Feb 26, 2021

pmutua, that doesn't work because it's only valid on Linux or from powershell. You're trying to run it from the Windows command line.

But here are two ways to get it to work:

  • you can literally run that command by passing it TO powershell on the DOS cmd line: powershell "docker rm $(docker ps -aq)"
  • or if running powershell at the cmd line strikes anyone as odd, we can do a variant of the longer command originally offered at the top of this gist, but we don't need to do it in a batch file. This would work: FOR /F %k in ('docker ps -aq') DO docker rm %k

Thank you

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