Skip to content

Instantly share code, notes, and snippets.

@daredude
Created June 5, 2016 10:53
Show Gist options
  • Select an option

  • Save daredude/045910c5a715c02a3d06362830d045b6 to your computer and use it in GitHub Desktop.

Select an option

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

Copy link
Copy Markdown

Thx!!!

@mastroiannim

Copy link
Copy Markdown

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

@dana-c0914

Copy link
Copy Markdown

Thanks!

@alonstar

Copy link
Copy Markdown

thank!

@dzek69

dzek69 commented Jul 12, 2019

Copy link
Copy Markdown

Thanks

@robece

robece commented Aug 23, 2019

Copy link
Copy Markdown

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

@egres82

egres82 commented Sep 21, 2019

Copy link
Copy Markdown

Thank you!!!

@HenryBol

Copy link
Copy Markdown

Super, thanks!!

@ppalni

ppalni commented Dec 2, 2019

Copy link
Copy Markdown

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

@katlimruiz

Copy link
Copy Markdown

docker system prune

worked now

@wodsonluiz

Copy link
Copy Markdown

Thanks!

@pistocop

Copy link
Copy Markdown

Thanks!

@mohammedalsayegh

Copy link
Copy Markdown

Thanks!

@sawich

sawich commented Sep 3, 2020

Copy link
Copy Markdown

Thanks!

@AndreiMireichyk

Copy link
Copy Markdown

Thanks!

@R0Wi

R0Wi commented Sep 23, 2020

Copy link
Copy Markdown

Thank you :-)

@ilanl

ilanl commented Nov 3, 2020

Copy link
Copy Markdown

Saved me lot of headaches !

@pmutua

pmutua commented Nov 19, 2020

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

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

pmutua commented Feb 26, 2021

Copy link
Copy Markdown

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

Thanks ! working !

@suthikhamsamut

Copy link
Copy Markdown

thanks so much

@quanganh2001

Copy link
Copy Markdown

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

@AkryosIT

AkryosIT commented Feb 3, 2024

Copy link
Copy Markdown

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