Skip to content

Managing Docker Images on Docker Hub using Docker Hub API

This guide will walk you through the steps to access, list, and remove images from Docker Hub using the Docker Hub API.

Step 1: Access Docker Hub API

To access the Docker Hub API, you need to authenticate using your Docker Hub credentials. You can use the following command to get a token:

bash
curl -u <username>:<password> "https://hub.docker.com/v2/users/login/" | jq -r .token

Replace <username> and <password> with your Docker Hub credentials. This command will return a token that you will use for subsequent API requests.

Step 2: List Existing Docker Images

To list all the Docker images in your Docker Hub repository, use the following command:

bash
curl -H "Authorization: JWT <token>" "https://hub.docker.com/v2/repositories/<username>/?page_size=100" | jq '.results[] | {name, namespace, repository_type, status}'

Replace <token> with the token obtained in Step 1 and <username> with your Docker Hub username. This command will display a list of all images along with their details.

Step 3: Remove Docker Images

To remove a specific Docker image from your Docker Hub repository, use the following command:

bash
curl -X DELETE -H "Authorization: JWT <token>" "https://hub.docker.com/v2/repositories/<username>/<repository>/tags/<tag>/"

Replace <token> with the token obtained in Step 1, <username> with your Docker Hub username, <repository> with the name of the repository, and <tag> with the tag of the image you want to remove.

Conclusion

You have successfully accessed the Docker Hub API, listed existing Docker images, and removed images from Docker Hub. You can now manage your Docker images more efficiently using the Docker Hub API.