Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing old / unused docker images

I'm using Sonatype Nexus as a Docker Registry and after a while, it got really big (new image with every CI build and some old projects).

I tried using "Purge unused docker manifests and images" task, but it doesn't seem to do anything.

like image 826
Matej Žerovnik Avatar asked Sep 13 '25 19:09

Matej Žerovnik


1 Answers

I remove the old docker images manually.

  1. get nexus-cli

    wget https://s3.eu-west-2.amazonaws.com/nexus-cli/1.0.0-beta/linux/nexus-cli
    
    chmod +x nexus-cli
    
  2. configure host

    ./nexus-cli configure
    
  3. show images

    ./nexus-cli image ls
    
  4. keep the latest 5 images

    ./nexus-cli image delete -name mlabouardy/nginx -keep 5
    
  5. A clean script

image_file=image.txt
CLI_HOME=/data/nexus3
KEEP_VERSION_NUM=5

$CLI_HOME/nexus-cli image ls > $image_file
sed -i '$d' $image_file


cat $image_file | while read line
do
    echo "start clean image:  $line"
    $CLI_HOME/nexus-cli image delete -name $line -keep $KEEP_VERSION_NUM
done
  1. create create docker - delete unsued manifests and images task

  2. create create admin -compact blob store task

like image 147
Ryan Miao Avatar answered Sep 15 '25 21:09

Ryan Miao