Skip to content

Instantly share code, notes, and snippets.

@daredude
Created June 5, 2016 10:53
Show Gist options
  • Save daredude/045910c5a715c02a3d06362830d045b6 to your computer and use it in GitHub Desktop.
Save daredude/045910c5a715c02a3d06362830d045b6 to your computer and use it in GitHub Desktop.
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
@yedincisenol
Copy link

Thanks!

@mmgil
Copy link

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
Copy link

Thank you!

@jcarloslr10
Copy link

Thx!!!

@mastroiannim
Copy link

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

@dana-c0914
Copy link

Thanks!

@alonstar
Copy link

thank!

@dzek69
Copy link

dzek69 commented Jul 12, 2019

Thanks

@robece
Copy link

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
Copy link

egres82 commented Sep 21, 2019

Thank you!!!

@HenryBol
Copy link

Super, thanks!!

@ppalni
Copy link

ppalni commented Dec 2, 2019

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

@katlimruiz
Copy link

docker system prune

worked now

@wodsonluiz
Copy link

Thanks!

@pistocop
Copy link

Thanks!

@mohammedalsayegh
Copy link

Thanks!

@sawich
Copy link

sawich commented Sep 3, 2020

Thanks!

@AndreiMireichyk
Copy link

Thanks!

@R0Wi
Copy link

R0Wi commented Sep 23, 2020

Thank you :-)

@ilanl
Copy link

ilanl commented Nov 3, 2020

Saved me lot of headaches !

@pmutua
Copy link

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
Copy link

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
Copy link

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

@pgsridhar
Copy link

Thanks ! working !

@suthikhamsamut
Copy link

thanks so much

@quanganh2001
Copy link

Thank you very much! This bat file has solved vmmem high CPU.

@AkryosIT
Copy link

AkryosIT commented Feb 3, 2024

just tried this and it works
foreach ($cnt in $(docker ps -aq)) {docker rm $cnt;Write-Host "$cnt deleted"}

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