0

Recently we found out that our Kubenetes nodes are using high disk space,after checking the nodes we found that the high disk space was due to docker images.

We know that if we run docker image prune -a command, it will remove all the unused images but it will also remove some unused images we need.

We checked if the image prune command supports removing only particular image and their tags(webapp:1, webapp:2 etc), it does not. Even though docker image ls command has this feature (docker image ls --filter reference=<image name>)

Is there a way to only prune particular images and their tags?

1 Answers1

0

You can actually do this with a for loop. Until someone else tells you how to do it with Docker, you can use this;

for image in $(docker image ls --filter reference=<image_name> | awk '{if (NR>1) {print $3}}'); do docker image rm $image; done

This command simply lists the relevant containers and sends their image ids to the remove command. To test it you can change the last part like this;

for image in $(docker image ls --filter reference=<image_name> | awk '{if (NR>1) {print $3}}'); do echo $image; done
yildirim
  • 1
  • 3