In this post, I will be discussing how to maintain our private Docker registry.
1. Check Available Repositories in the Registry
We can use the Docker Registry HTTP API to get a list of repositories.
Using the Docker Registry API:
Step 1: First, you need to ensure your registry is accessible over the network.
Step 2: Use
curl
or any HTTP client to make an API request to list all repositories:
- Replace
username
andpassword
with your registry credentials. - Replace
your-domain.com
with your Docker registry domain or IP.
This will return a JSON object containing a list of repositories in your Docker registry:
2. Check Available Tags in a Repository
Once we know the repository names, we can list the tags for a specific repository:
- Step 1: Use the following API call to get the tags of a specific repository:
curl -u username:password -X GET https://your-domain.com/v2/repository-name/tags/list
3. Delete a Repository or Specific Tag
The Docker Registry API does not support removing an entire repository directly, but we can delete specific image tags, which effectively removes the image from the registry.
Using the Registry API to Delete Manifests (Tags):
Step 1: Find the digest of the image tag you want to delete:
curl -u username:password -I -H "Accept: application/vnd.docker.distribution.manifest.v2+json" https://your-domain.com/v2/repository-name/manifests/tag-name
This will return headers, including the image's digest in thedocker-content-digest
header:- Step 2: Use the digest to delete the image:curl -u username:password -X DELETE https://your-domain.com/v2/repository-name/manifests/sha256:abc123def456...
You might get the error ("The operation is unsupported."
). This occurs because by default, the Docker Registry does not support deletion of manifests. To enable deleting images or tags in the Docker registry, you need to modify the registry configuration to allow deletions.
If you're using Docker Compose, add the environment variable in your docker compose file REGISTRY_STORAGE_DELETE_ENABLED: true
After modifying the configuration, we need to restart the Docker registry to apply the changes:
Now your delete will be successful.
This deletes the specific image tag. After deleting tags, the data might still remain in the registry until a garbage collection is run.
4. Garbage Collection to Fully Remove Deleted Repositories/Tags
After deleting manifests or tags, run garbage collection to clean up the registry:
Step 1: Stop your Docker Registry (you need to ensure no push or pull operations happen while the GC is running):
$ docker-compose downStep 2: Run Garbage Collection inside the registry container:
$ docker run --rm -v /path/to/registry/data:/var/lib/registry registry:2 bin/registry garbage-collect /etc/docker/registry/config.yml
Replace/path/to/registry/data
with the path to your registry data, usually mounted in the container.Step 3: Restart the registry:
$ docker-compose up -d
No comments:
Post a Comment