How to remove unused docker images in a swarm?

We have a system in which the user can install some docker containers. We have no limit to what he can establish. After some time, we need to clean - delete all images that are not used in the swarm.

What would be the solution for this using the remote docker API?

Our idea is to have a background image-collector-collector that:

  • displays all images
  • try to remove some
  • If this fails, just ignore

Would that make sense? Would it affect the swarm?

+4
source share
3 answers

A cleaner way to list and (try) delete all images

docker rmi $(docker images -q) , @tpbowden, . -q|--quiet .

( )

, swarm run deleted-image, :

  • (< /" > )
  • , , (< /" > ).

"dangling = true":

--filter "dangling=true". swarm images -q --filter "dangling=true" .


. :

, ?

. - , , : docker images --format='{{.CreatedSince}}:{{ .ID}}'. ... , grep "months", cut -d ':' -f 2.

:

docker rmi $(docker images --format='{{.CreatedSince}}:{{ .ID}}' G months | cut -d ':' -f 2)

, Swarm, Swarm, Swarm.

, swarm pull image:tag ! . , .

, . ", " AFAIK.

+5
docker images | tail -n+2 | awk '{print $3}' | xargs docker rmi

, , 3- ( ) . Docker , .

"" , Docker API , , .

0

All you need is prune '

$ docker image prune --filter until=72h --force --all
0
source

All Articles