Delete the image operation of none in docker images

Delete the image operation of none in docker images

Since I usually use the docker build command to generate an image, sometimes due to frequent code updates, a lot of none images will be generated. Recently, I want to clear them out.

So I wrote the following script:

docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker stop
docker ps -a | grep "Exited" | awk '{print $1 }'|xargs docker rm
docker images|grep none|awk '{print $3 }'|xargs docker rmi

Supplement: Docker deletes all none images or stopped containers

After repeated builds in docker, many none images will remain. The following command deletes all none images in one click.

docker rmi `docker images | grep '<none>' | awk '{print $3}'`

A simpler way

docker rmi `docker images -q -f dangling=true`

or

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

Remove all stopped containers

docker rm $(docker ps -a -q)

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • Talk about the issue of replacing docker (shim) with containerd in kubernetes1.20
  • How to keep running after exiting Docker container
  • Docker removes abnormal container operations
  • Goodbye Docker: How to Transform to Containerd in 5 Minutes
  • Docker dynamically exposes ports to containers
  • Implementation of local migration of docker images
  • Solve the problem of docker images disappearing
  • Docker image cannot be deleted Error: No such image: xxxxxx solution
  • How to delete an image in Docker
  • Naming containers and images in Docker

<<:  Abbreviation of HTML DOCTYPE

>>:  js array fill() filling method

Recommend

Docker image management common operation code examples

Mirroring is also one of the core components of D...

Detailed explanation of the solution to the nginx panic problem

Regarding the nginx panic problem, we first need ...

How to use and limit props in react

The props of the component (props is an object) F...

MySQL learning notes help document

View system help help contents mysql> help con...

Detailed explanation of the basic usage of the img image tag in HTML/XHTML

The image tag is used to display an image in a we...

Detailed explanation of InnoDB storage files in MySQL

Physically speaking, an InnoDB table consists of ...

Selection and thinking of MySQL data backup method

Table of contents 1. rsync, cp copy files 2. sele...

Introduction to HTML Chinese Character Encoding Standard

In HTML, you need to specify the encoding used by...

Detailed example code of mysql batch insert loop

background A few days ago, when I was doing pagin...

Detailed examples of Zabbix remote command execution

Table of contents one. environment two. Precautio...

How to solve the error of connecting to the database when ServerManager starts

Servermanager startup connection database error R...

How to handle MySQL numeric type overflow

Now, let me ask you a question. What happens when...

How to quickly deploy an Elasticsearch cluster using docker

This article will use Docker containers (orchestr...