Delete mirroring operation for none in docker images

  • 2021-10-16 05:33:30
  • OfStack

Usually, 1 directly uses docker build command to generate a mirror image. Sometimes, due to the code and new frequency, a lot of none image will be generated. Recently, I want to clear 1.

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 removes all none mirrored or stopped containers

After docker repeats build, many none images will remain. The following command 1 key deletes all none images

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

A simpler approach

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


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

Delete all stopped containers

docker rm $(docker ps -a -q)

Related articles: