Skip to content

Instantly share code, notes, and snippets.

@rpratesh
Last active February 28, 2018 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpratesh/7da3db32f7b1d1953f28aa8bcd8284a9 to your computer and use it in GitHub Desktop.
Save rpratesh/7da3db32f7b1d1953f28aa8bcd8284a9 to your computer and use it in GitHub Desktop.
To remove dangling Docker containers and images

This worked for me on Ubuntu 16.04 with Docker version 17.12.0-ce

Before deleting all the containers, force stop them:
$ docker ps -q -a | xargs docker stop

Then delete the containers using:
$ docker ps -q -a | xargs docker rm

Now delete all the dangling images using:
$ docker rmi $(docker images | grep “^<none>” | awk ‘{print $3}’)

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