Skip to content

Instantly share code, notes, and snippets.

@jgornick
Created May 20, 2016 19:07
Show Gist options
  • Save jgornick/d5e20503c37e04a7a428b433dbf4993d to your computer and use it in GitHub Desktop.
Save jgornick/d5e20503c37e04a7a428b433dbf4993d to your computer and use it in GitHub Desktop.
Docker: Cleanup (Remove all exited containers and dangling images)
#!/bin/bash
docker rm $(docker ps -q -f status=exited)
docker rmi $(docker images -q -f dangling=true)
@jgornick
Copy link
Author

@RSwarnkar
Copy link

Did not worked for Docker for Windows:

unknown shorthand flag: 'q' in -q
See 'docker rm --help'.

@HBrinkhof
Copy link

@RSwarnkar, I had a similar issue, my problem got solved by this:
https://stackoverflow.com/questions/53559545/docker-unknown-shorthand-flag-a-in-aq

Basically, if you try
docker rmi $(docker images -q -f dangling=true)
you'll get that error, because $(docker images -q -f dangling=true) is a linux command. You'll need to change it to something like this:

FOR /f "tokens=*" %i IN ('docker images -q -f dangling=true') DO docker rmi %i

Hope this helps you out.

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