How to delete a container image from local container registry ?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 9
  • Red Hat Enterprise Linux 10
  • docker
  • podman

Issue

  • Local container registry keeps occupying a space and would require an image clean up

Resolution

  • How to implement a simple personal/private Linux container image registry for internal use
  • Make sure to include the environmental variable REGISTRY_STORAGE_DELETE_ENABLED: "true" when creating the registry container. This is mandatory to be able to remove the images in the future
  • The images in this registry can not be deleted by docker/podman rmi but can only be deleted using API
    One other way to remove the images is by directly getting into the container and removing the related files which isn't recommended since there is a possibility to remove the files that would be in use by other images
  • Follow the below steps in order to remove the images using API,
    • Run the command curl -v -u "<username>:<password>" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X HEAD https://<registry-ip:port>/v2/<image-name>/manifests/<tag> where, <username> and <password> corresponds to the registry credentials
    • Running this would fetch a response which would contain the value of docker-content-digest and would look something similar to sha256:fe5cdc0996907f830d34ac17125482c16969f7ff4310b860ef9106f782d077e7(This is just an example and the actual value would differ). Note this and use it in the next step
    • Run the command curl -u "<username>:<password>" -X DELETE https://<registry-ip:port>/v2/<image-name>/manifests/<docker-content-digest> to delete the particular image from the registry

Note:
- This solution is applicable only for the registry deployed using the container image mentioned in the article and will not be applicable for Red Hat Quay registries
- The article stated in this solution contains a third party container image and is not supported by Red Hat for any issues. This article provides a way to remove the image and in case of any issues, the provider of the image should be contacted; Red Hat would not be accountable in any scenarios

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments