# How to delete a docker image in Nexus3 Repo programmatically?

**URL:** <https://community.sonatype.com/t/how-to-delete-a-docker-image-in-nexus3-repo-programmatically/14701>\
**Category:** Sonatype Nexus Repository\
**Tags:** rest, nexus-repository\
**Created:** [March 27, 2025, 8:26pm UTC](https://community.sonatype.com/t/how-to-delete-a-docker-image-in-nexus3-repo-programmatically/14701 "2025-03-27T20:26:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karl\_Cai](https://avatars.discourse-cdn.com/v4/letter/k/22d042/32.png) [@Karl\_Cai](https://community.sonatype.com/u/Karl_Cai)\
**Post date:** [March 27, 2025, 8:26pm UTC](https://community.sonatype.com/t/how-to-delete-a-docker-image-in-nexus3-repo-programmatically/14701/1 "2025-03-27T20:26:55Z")

</div>

Sorry for this seems to be the very basic question, but somehow I just can’t make it work.

In my most recently updated ubuntu22.04, I installed nexus3:latest (I think it is 3.78.2) so to use it as a docker repo. I used this command:  
docker run -d --name nexus -p 8081:8081 -p 8082:8082 -v /opt/nexus-data:/nexus-data --restart unless-stopped sonatype/nexus3

Everything works fine: I can login to the UI, login as admin and then change password. I am create a docker hosted repo and put a docker image into this repo, and pull it, via docker push/pull and curl/API. But I could not delete it (I had this problem with my 8+ year old nexus docker container, in which I could not find a way to delete, and this is the reason I am trying to upgrade to ubuntu22.04 + latest nexus3). Chatgpt said I should do something like this:

1. get the digest first. This works for me:  
curl -s -u admin -X GET -I -H “Accept: application/vnd.docker.distribution.manifest.v2+json” http://:8082/v2/dockerepo2204/my\_docker\_img/manifests/latest | grep “Docker-Content-Digest”  
===\> Docker-Content-Digest: sha256:dd1c2b2f417713a3cfcb44af6c62fba79feb0453eccbfcd87ccf5f1d8e012997
2. use this command to delete.  
curl -u admin -X DELETE http://\<my\_ip\>:8082/v2/dockerepo2204/my\_docker\_img/manifests/sha256:dd1c2b2f417713a3cfcb44af6c62fba79feb0453eccbfcd87ccf5f1d8e012997  
This doesn’t work. Nothing returned. In face, If I change the digest 2997 to 2999, a random digest, nothing is reported as well.
3. Chatgpt then told me that I have to set ‘“allowDeleteApi”: true’. But the way it provided, neither UI or curl way worked for me.

So my question: how do I delete a docker image in sonatype/nexus3 docker repo programmatically (not via UI) so I can automatic this step? Any related API pointers or a working example would be very helpful.

Sorry if this question was asked and answered before. I did a quick search but could not find the answer. Thank you!

---

<div class="post-metadata">

**Author:** ![mpiggott](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mpiggott](https://community.sonatype.com/u/mpiggott)\
**Post date:** [March 28, 2025, 1:24pm UTC](https://community.sonatype.com/t/how-to-delete-a-docker-image-in-nexus3-repo-programmatically/14701/2 "2025-03-28T13:24:31Z")

</div>

> [@Karl\_Cai](#):
>
> This doesn’t work. Nothing returned. In face, If I change the digest 2997 to 2999, a random digest, nothing is reported as well.

What do you mean when you say nothing returned

---

<div class="post-metadata">

**Author:** ![Karl\_Cai](https://avatars.discourse-cdn.com/v4/letter/k/22d042/32.png) [@Karl\_Cai](https://community.sonatype.com/u/Karl_Cai)\
**Post date:** [March 28, 2025, 8:28pm UTC](https://community.sonatype.com/t/how-to-delete-a-docker-image-in-nexus3-repo-programmatically/14701/3 "2025-03-28T20:28:41Z")

</div>

I am confused by the waiting. I was told that after my first successful post, follow-up post will be accepted automatically. This is not my first post. What it is waited again? Thanks.

---

<div class="post-metadata">

**Author:** ![Karl\_Cai](https://avatars.discourse-cdn.com/v4/letter/k/22d042/32.png) [@Karl\_Cai](https://community.sonatype.com/u/Karl_Cai)\
**Post date:** [March 28, 2025, 8:28pm UTC](https://community.sonatype.com/t/how-to-delete-a-docker-image-in-nexus3-repo-programmatically/14701/4 "2025-03-28T20:28:44Z")

</div>

Sorry, I meant that nothing is shown in the screen after running that command. I should have used the -i option for curl. I can’t see the other claim I made that changing the digests to a random value doesn’t output anything.

After more testing, it seem to me that in my nexus 3.78.2 community version I can use this:  
curl -u admin:xxxxxx -X DELETE ‘[http://localhost:8081/service/rest/v1/components/](http://localhost:8081/service/rest/v1/components/)’

or this:  
curl -si -u admin:xxxxxx -X DELETE [http://localhost:8082/v2/dockerepo2204/my\_docker\_image/manifests/sha256:dd1c2b2f417713a3cfcb44af6c62fba79feb0453eccbfcd87ccf5f1d8e012997](http://localhost:8082/v2/dockerepo2204/my_docker_image/manifests/sha256:dd1c2b2f417713a3cfcb44af6c62fba79feb0453eccbfcd87ccf5f1d8e012997)

to delete a docker image. The difference is: using the first/components, in the UI you can still see the deleted image, but the second/manifests way UI is cleaned up. In both cases, the blobs are not cleaned up.

So my follow-up questions, for the goal of the original task (delete an docker image completely):

1. are these two ways both supported? If yes, what’s the difference exactly (other than the above observation)?
2. more importantly, how to clean the data/blobs after these commands so I can reclaim my disk space?

Again, from Chatgpt, I got this:

To clean up:

1. **Wait 1 day** (blobs must be unused for 24h)
2. Run a **“Admin - Compact blob store”** task in Nexus

Is this the right step? There are so many different task types and I am not sure exactly who is what.

Thank you!

---

<div class="post-metadata">

**Author:** ![jzora](https://yyz1.discourse-cdn.com/flex047/user_avatar/community.sonatype.com/jzora/32/4197_2.png) [@jzora](https://community.sonatype.com/u/jzora)\
**Post date:** [March 28, 2025, 9:35pm UTC](https://community.sonatype.com/t/how-to-delete-a-docker-image-in-nexus3-repo-programmatically/14701/5 "2025-03-28T21:35:28Z")

</div>

Sorry, Karl. I’ve updated your permissions so that your posts won’t be held in a queue.

---

<div class="post-metadata">

**Author:** ![brandonh](https://avatars.discourse-cdn.com/v4/letter/b/c6cbf5/32.png) [@brandonh](https://community.sonatype.com/u/brandonh)\
**Post date:** [March 31, 2025, 1:49pm UTC](https://community.sonatype.com/t/how-to-delete-a-docker-image-in-nexus3-repo-programmatically/14701/6 "2025-03-31T13:49:52Z")

</div>

Hi Karl,  
To fully delete the docker image from the blob store disk, you need to setup two admin tasks in gui to delete it fully. Read through the " Required Final Steps to Completely Delete Docker Assets From Disk" at [https://support.sonatype.com/hc/en-us/articles/360009696054-How-to-delete-docker-images-from-Nexus-Repository-3](https://support.sonatype.com/hc/en-us/articles/360009696054-How-to-delete-docker-images-from-Nexus-Repository-3) . Have those two tasks run in order to reclaim the space from the blob store disk. You might also probably want to setup a task for “Docker - Delete incomplete uploads” before running the other two as well to cleanup any images that were incomplete.
