4

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.

4 Answers4

3

I remove the old docker images manuely.

  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

Ryan Miao
  • 471
  • 6
  • 13
2

You will need to setup a Cleanup Policy.

enter image description here

Noumenon
  • 5,099
  • 4
  • 53
  • 73
Arockiasmy K
  • 343
  • 3
  • 10
0

Create a cleaning policy (for example: 15 days after modification) - Caveat: docker push of the same hash is not modification

For each your registry (Nexus calls it "repository of type Docker"):

  • Setup the cleaning policy of your choice
  • The cleanup task
    • Create
    • Run until finish
    • Check the nexus3.log file
  • The "remove unused manifests and images"
    • Create
    • Run until finish
    • Check the nexus3.log file
  • The "compact blob" task
    • Create
    • Run until finish
    • Check the nexus3.log file
  • The space should be freed now
  • Don't use Nexus in your next project
  • ...
  • Profit
kubanczyk
  • 5,184
  • 1
  • 41
  • 52
-7

For removing old and / unused docker images you must use below command:

docker images purne

documents: https://docs.docker.com/engine/reference/commandline/image_prune/

arsalanio
  • 40
  • 6
  • 1
    This only works for local docker images. My question was regarding Sonatype Nexus repository. My repository is taking too much images and I'm wondering how to purge/clean it. – Matej Žerovnik Feb 20 '18 at 21:12