Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove docker images added to microk8s image cache?

I have imported some docker images to microk8s image cache for local kubernetes deployment using,

microk8s.ctr -n k8s.io image import <docker_image_name>.tar

how can I remove some of the unwanted images from this cache? Is there any command for that?

Thanks in advance!

like image 996
anju Avatar asked Nov 15 '19 05:11

anju


2 Answers

If you want to delete all custom added images from the built-in library, you can do this:

# get all images that start with localhost:32000, output the results into image_ls file
sudo microk8s ctr images ls name~='localhost:32000' | awk {'print $1'} > image_ls 
# loop over file, remove each image
cat image_ls | while read line || [[ -n $line ]];
do
    microk8s ctr images rm $line
done;

Yes, I've used David Castros comment as a base, but since it did not work for Microk8s, I needed to adapt it a bit.

like image 64
Marco Avatar answered Nov 01 '22 12:11

Marco


With --help you can see the that there is a remove option:

> microk8s.ctr -n k8s.io images --help
NAME:
   ctr images - manage images

USAGE:
   ctr images command [command options] [arguments...]

COMMANDS:
     check       check that an image has all content available locally
     export      export an image
     import      import images
     list, ls    list images known to containerd
     pull        pull an image from a remote
     push        push an image to a remote
     remove, rm  remove one or more images by reference
     label       set and clear labels for an image

OPTIONS:
   --help, -h  show help

So you can see the running containers with:

 microk8s.ctr -n k8s.io containers ls

And later remove images with:

 microk8s.ctr -n k8s.io images rm "image_ref"
like image 26
Matt Avatar answered Nov 01 '22 13:11

Matt