Skip to content

Instantly share code, notes, and snippets.

@r14c
Forked from ngpestelos/remove-docker-containers.md
Last active January 22, 2016 22:14
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 r14c/7f6b3d795336ffa35060 to your computer and use it in GitHub Desktop.
Save r14c/7f6b3d795336ffa35060 to your computer and use it in GitHub Desktop.
Remove unused Docker containers and images

Delete all containers

$ [sudo] docker ps -q -a | xargs [sudo] docker rm

Notes

-q prints only the container IDs, -a prints all containers.

Notice that it uses xargs to issue a remove container command for each container ID.

Delete all untagged images

$ [sudo] docker rmi $([sudo] docker images | grep "^<none>" | awk '{print $3}')

Notes

awk must use a single quote or the curly brackets will be interpreted by the shell.

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