Skip to content

Instantly share code, notes, and snippets.

@velppa
Forked from ngpestelos/remove-docker-containers.md
Last active May 30, 2019 21:29
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 velppa/60e8c0aad4cd7a3d0241cef5485bc077 to your computer and use it in GitHub Desktop.
Save velppa/60e8c0aad4cd7a3d0241cef5485bc077 to your computer and use it in GitHub Desktop.
Docker cheat sheet

Delete all containers

docker ps -q -a | xargs docker rm

-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

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

awk must use a single quote (this filters all image IDs)

Delete exited containers

docker ps -a | grep Exited | awk '{print $1}' | xargs docker rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment