Script to delete all images from hosted docker repository on nexus 3.1

3,088 views
Skip to first unread message

rohit gupta

unread,
Apr 18, 2017, 9:55:20 AM4/18/17
to Nexus Users
Hi All,

We configured a docker repository on nexus OSS 3.1 protected by an SSL certificate and are able to successfully pull/push images from it.

Now our repo size is growing day by day and we have a disk limit of 200 GB. So we need a scheduled task now to clean up this docker registry.

Is there a proven/tested script which can delete all images from docker repository and hence also clear all space taken up by the blobstore?

Note:- I tried the groovy script https://gist.github.com/lukewpatterson/bf9d19410094ea8bced1d4bb0523b67f given in a bug Nexus -9263 but it doesnt actually work.

Would really appreciate any help as it has kinda become a blocker at the moment

Thanks,
Rohit

Yunior Pupo Peña

unread,
Apr 18, 2017, 12:43:32 PM4/18/17
to rohit gupta, Nexus Users
Maybe the best way is to create a separate blob store for the docker repository and delete/create the repository and the blob store on each cleanup.

--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users...@glists.sonatype.com.
To post to this group, send email to nexus...@glists.sonatype.com.
To view this discussion on the web visit https://groups.google.com/a/glists.sonatype.com/d/msgid/nexus-users/69d3e0ba-8a30-4f3a-8148-de606dfeb70a%40glists.sonatype.com.
For more options, visit https://groups.google.com/a/glists.sonatype.com/d/optout.

Yunior Pupo Peña

unread,
Apr 18, 2017, 2:33:33 PM4/18/17
to rohit gupta, Nexus Users
I hasn't tried to delete the folder where the blob store is located on the filesystem.

You can follow this steps to perform the cleanup:

1- Delete the hosted docker registry (Nexus UI)
2- Delete the blob store in which was located the docker registry (the ui only lets perform this action if there is no other repo in this blob store)
3- Verify that the physical location of the blob store was deleted (typically located at  /sonatype-work/nexus3/blobs/<name>)
4- Create the new blob store (with the same name)
5- Create the hosted docker registry (with the same id as before) and assign the storage location to the created blob store.

I don't have any experience creating groovy scripts for nexus, but this sequence of actions should be trivial to implement.

Regards

On Tue, Apr 18, 2017 at 12:49 PM rohit gupta <rohitg...@gmail.com> wrote:
Thanks Yunior! 

Sounds good.

Actually, I tried to remove default blob store manually under /sonatype-work/nexus3/blobs/default, created a new one and restarted nexus but the docker images were still there! There are lot of other folders under /sonatype-work/nexus3/blobs though.

Have you tried it or how do we remove blobstore to ensure there is no image reference? 

Cheers,
Rohit

Jeffry Hesse

unread,
Apr 18, 2017, 4:58:40 PM4/18/17
to rohit gupta, Nexus Users
A few things:

Firstly: We've added a task that allows you to purge dangling Docker images and layers in Nexus 3.2, you might want to check that out first (this is more for the posterity of others).

Secondly: http://stackoverflow.com/questions/41828632/delete-repository-via-nexus-3-rest-api (this is how you delete a repo using the script manager, at a very basic level). I think from there internally Nexus will clean up after you, after a period of time (I'm a bit fuzzy here, myself).

Thirdly: What doesn't work in that script for you? I'll take a gander at it as time provides :)

Jeffry

--

rohit gupta

unread,
Apr 19, 2017, 2:57:57 AM4/19/17
to Jeffry Hesse, Nexus Users
Thanks Jeffry/Yunior,

- We are on nexus 3.1 so we will have to upgrade to 3.2(which is a manual task). I had installed nexus 3.2 on my local m/c and saw that 'Purge unused Docker images and manifests' task has been added.
  
- The script to delete a repo works perfectly fine but just that it doesnt clean up the underlying blobstore! So essentially that doesnt help.

Btw, I have played around with a groovy script which I am currently testing but it seems to do the job. I will update on this discussion trail if that works. So essentially we want to avoid upgrading to nexus 3.2 and do tricky stuff like deleting blobstore etc.

Cheers,
Rohit




On Wed, Apr 19, 2017 at 2:28 AM, Jeffry Hesse <jhe...@sonatype.com> wrote:
A few things:

Firstly: We've added a task that allows you to purge dangling Docker images and layers in Nexus 3.2, you might want to check that out first (this is more for the posterity of others).

Secondly: http://stackoverflow.com/questions/41828632/delete-repository-via-nexus-3-rest-api (this is how you delete a repo using the script manager, at a very basic level). I think from there internally Nexus will clean up after you, after a period of time (I'm a bit fuzzy here, myself).

Thirdly: What doesn't work in that script for you? I'll take a gander at it as time provides :)

Jeffry


On Tue, Apr 18, 2017 at 5:55 AM rohit gupta <rohitg...@gmail.com> wrote:
Hi All,

We configured a docker repository on nexus OSS 3.1 protected by an SSL certificate and are able to successfully pull/push images from it.

Now our repo size is growing day by day and we have a disk limit of 200 GB. So we need a scheduled task now to clean up this docker registry.

Is there a proven/tested script which can delete all images from docker repository and hence also clear all space taken up by the blobstore?

Note:- I tried the groovy script https://gist.github.com/lukewpatterson/bf9d19410094ea8bced1d4bb0523b67f given in a bug Nexus -9263 but it doesnt actually work.

Would really appreciate any help as it has kinda become a blocker at the moment

Thanks,
Rohit

--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users+unsubscribe@glists.sonatype.com.

Rich Rousseau

unread,
Jun 19, 2017, 4:30:29 PM6/19/17
to Nexus Users, jhe...@sonatype.com, rohitg...@gmail.com
Did you get anywhere with the script you were creating?


On Wednesday, April 19, 2017 at 1:57:57 AM UTC-5, rohit gupta wrote:
Thanks Jeffry/Yunior,

- We are on nexus 3.1 so we will have to upgrade to 3.2(which is a manual task). I had installed nexus 3.2 on my local m/c and saw that 'Purge unused Docker images and manifests' task has been added.
  
- The script to delete a repo works perfectly fine but just that it doesnt clean up the underlying blobstore! So essentially that doesnt help.

Btw, I have played around with a groovy script which I am currently testing but it seems to do the job. I will update on this discussion trail if that works. So essentially we want to avoid upgrading to nexus 3.2 and do tricky stuff like deleting blobstore etc.

Cheers,
Rohit



On Wed, Apr 19, 2017 at 2:28 AM, Jeffry Hesse <jhe...@sonatype.com> wrote:
A few things:

Firstly: We've added a task that allows you to purge dangling Docker images and layers in Nexus 3.2, you might want to check that out first (this is more for the posterity of others).

Secondly: http://stackoverflow.com/questions/41828632/delete-repository-via-nexus-3-rest-api (this is how you delete a repo using the script manager, at a very basic level). I think from there internally Nexus will clean up after you, after a period of time (I'm a bit fuzzy here, myself).

Thirdly: What doesn't work in that script for you? I'll take a gander at it as time provides :)

Jeffry


On Tue, Apr 18, 2017 at 5:55 AM rohit gupta <rohitg...@gmail.com> wrote:
Hi All,

We configured a docker repository on nexus OSS 3.1 protected by an SSL certificate and are able to successfully pull/push images from it.

Now our repo size is growing day by day and we have a disk limit of 200 GB. So we need a scheduled task now to clean up this docker registry.

Is there a proven/tested script which can delete all images from docker repository and hence also clear all space taken up by the blobstore?

Note:- I tried the groovy script https://gist.github.com/lukewpatterson/bf9d19410094ea8bced1d4bb0523b67f given in a bug Nexus -9263 but it doesnt actually work.

Would really appreciate any help as it has kinda become a blocker at the moment

Thanks,
Rohit

--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users...@glists.sonatype.com.
Reply all
Reply to author
Forward
0 new messages