Skip to content

Instantly share code, notes, and snippets.

@adamatti
Forked from ngpestelos/remove-docker-containers.md
Last active November 1, 2019 16:51
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 adamatti/0a2c8e4c72cc4d3059462b173b6a1331 to your computer and use it in GitHub Desktop.
Save adamatti/0a2c8e4c72cc4d3059462b173b6a1331 to your computer and use it in GitHub Desktop.
How to remove unused Docker containers and images #docker
  1. 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

  1. Delete all untagged images

     $ docker rmi $(docker images | grep “^<none>” | awk ‘{print $3}’)
    

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

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