Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.

If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!

deleting docker images via REST API



  • I am trying to use a PowerShell script to experiment with deleting docker images using the recently introduced REST API. When i issue the delete operation it returns a 401 error. I thus am assumed i needed to pass an API key. So i generated one with all permissions (overkill but it wasn't obvious which specific ones would apply). I passed that as a header and there was no change.

    The Uri value is the same one i used on a GET which returned the info on the image (config. digest, image layers etc)

    Invoke-RestMethod -Method DELETE -Uri https://MyServer/v2/Main/bhge/dcfr-microservices/manifests/280307 -ErrorVariable RestError -ErrorAction SilentlyContinue

    then went to

    Invoke-RestMethod -Method DELETE -Uri https://MyServer/v2/Main/bhge/dcfr-microservices/manifests/280307 -Headers @{"X-ApiKey" = "DdRBo6_mbzH80XEpXSfz" } -ErrorVariable RestError -ErrorAction SilentlyContinue

    i also tried a few other permutations but all end up with 401 errors.

    How should I really be doing this?


  • inedo-engineer

    Hello @James-McAllister_0459

    For the API key, use HTTP basic auth with api as the username and the API key as the password. You can also obtain a token via the Docker auth flow, but that's much more complicated.

    The manifest must be deleted by digest, not tag, so the URL should have /manifests/sha256: in it rather than just /manifests/ followed by a tag.



  • @James-McAllister_0459 said in deleting docker images via REST API:

    Invoke-RestMethod

    With that help i can now delete when i enter a digest. I had to switch to using Invoke-WebRequest rather than Invoke-RestMethod to get the response headers so i actually get the correct digest (read the docs again :-)

    Is there any way to get the published date or created date of the image from a REST api?

    I can see i could get it from the database and a join between the DockerImages and DockerImageTags tables.


  • inedo-engineer

    @James-McAllister_0459 said in deleting docker images via REST API:

    Is there any way to get the published date or created date of the image from a REST api?

    The Docker API in ProGet doesn't (currently) return a Last-Modified header, but depending on which date you want, it can still be accessed:

    Published date can be accessed via the native API using the tables you identified. However, this API is generated directly from internal ProGet database procedures, so this may break in the (unlikely) event that ProGet's Docker database structure changes.

    Created date is a property of the image, which is embedded in the manifest's config field. Inside the JSON blob referenced by the manifest, the creation date of the image is in a field named created. This is optional in the Docker specification, but if you're building your own images, it should always be present.


Log in to reply
 

Inedo Website HomeSupport HomeCode of ConductForums GuideDocumentation