docker-registry icon indicating copy to clipboard operation
docker-registry copied to clipboard

add feature to cleanup docker registry storage:remove history images

Open qxo opened this issue 11 years ago • 3 comments

add feature to cleanup docker registry storage:remove history images The blow script work fine for me :)

#!/bin/bash
# script for delete history images
d="";
if [ -z "$1" ] ; then
 echo "please input your docker registry store location:";
 read d;
else
 d=$1;
fi
echo "docker registry store location:$d";
echo "ready go ... ?  [ press any key to continue]";
read o;
if [ -d "$d"  -a -d "$d/images" ]  ; then
  images=$( ls -l $d/images | awk '{print $9}') ;
  c=0 ; c1=1; l="";
  for x in $images ;
  do
      let c+=1 ;
      echo "checking image $c:$x";
      b1=$( find $d/images  -type f \( -name "json" -o -name 'ancestry' \)  -path "./$x" -prune   -exec grep "\\s*$x\\s*"  -l {} \;) ;
      b2=$( find $d/repositories  -type f \( -name "json" -o -name 'ancestry' -o -name '_index_images' \)    -exec grep "\\s*$x\\s*"  -l {} \;);
      if [ -z "$b1" -a -z "$b2" ] ;  then
         let c1+=1;
         echo "no references images$c1:$x";
         if [ -n "$l" ] ; then l="$l "; fi;
         l=$l$x;
      fi ;
  done ;
  if [ -n "$l" ] ; then
   for x in $l ; do echo $x; done;
   echo "found images : $c1";
   echo "Are you sure for delete these images?[Y=yes]"; read input1;
   if [ "$input1" = "Y" ] ; then
      echo "before cleanup du -sm $d/images:$(du -sm $d/images)";
      for x in $l ; do echo $x ; rm -r "$d/images/$x" ; done ;
      echo "after cleanup du -sm $d/images:$(du -sm $d/images)";
   fi
  else
    echo "found nothing to cleanup."
    echo " du -sm $d/images:$(du -sm $d/images)";
  fi
else
 echo "dir:$d not exists!"
fi

qxo avatar Aug 14 '14 05:08 qxo

On Wed, Aug 13, 2014 at 10:30:01PM -0700, qxo wrote:

add feature to cleanup docker registry storage:remove history images

For built-in cleanup (where you don't need to run a script by hand), see #409.

wking avatar Aug 14 '14 15:08 wking

At #223,I found @shepmaster and @bjaglin scripts solve my problem:) https://gist.github.com/bjaglin/1ff66c20c4bc4d9de522

https://gist.github.com/shepmaster/53939af82a51e3aa0cd6

and improve the scripts:

https://gist.github.com/qxo/db0c31a67511625610f6

qxo avatar Aug 15 '14 06:08 qxo

layout in docker registry v2 has changed... this doesn't work anymore. Has there been improvement in the registry v2 to support this feature now?

streamnsight avatar Aug 05 '16 17:08 streamnsight