Summary of Docker's common clear container image command

  • 2020-05-30 21:26:23
  • OfStack

preface

Docker is a very interesting project. It claims to make it easier to deploy servers, but I'm sure there's some hype. But in practice, I think Docker's performance is remarkable. This article summarizes some of the common commands that Docker USES to clean up container images. Here's a look.

Kill all containers in the running state


docker kill $(docker ps -q)

Delete all containers that have been stopped


docker rm $(docker ps -a -q)

Delete all images of the 'untagged/dangling\' () state


docker rmi $(docker images -q -f dangling=true)

Delete all images:


docker rmi $(docker images -q)

Create aliases for these commands:


# ~/.bash_aliases

# Kill all running containers.
alias dockerkillall=\'docker kill $(docker ps -q)\'

# Delete all stopped containers.
alias dockercleanc=\'printf \"n>>> Deleting stopped containersnn\" && docker rm $(docker ps -a -q)\'

# Delete all untagged images.
alias dockercleani=\'printf \"n>>> Deleting untagged imagesnn\" && docker rmi $(docker images -q -f dangling=true)\'

# Delete all stopped containers and untagged images.
alias dockerclean=\'dockercleanc || true && dockercleani\'

Resources: https: / / www calazan. com/docker - cleanup - commands /

conclusion


Related articles: