Docker private registry setup and image query api’s

Dheeraj kumar
Jun 1, 2021

In this blog, we will learn about how to setup a docker private registry and setup authentication as well through docker.

Run this Dockerfile to create your registry image and run it.

FROM registry:2
RUN mkdir -m 777 data auth
ENV REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/data
ENV REGISTRY_AUTH htpasswd
ENV REGISTRY_AUTH_HTPASSWD_REALM Registry
ENV REGISTRY_AUTH_HTPASSWD_PATH /auth/registry.password
RUN apk update && apk add apache2-utils
RUN cd auth && htpasswd -b -B -c registry.password admin admin
RUN htpasswd -b registry.password dev dev@dev
EXPOSE 5000

Command to build & run the registry image:

docker build -t local_registry .
docker run -p 5000:5000 -d -v /data:/data local_registry

Api’s to query the Docker images stored in the registry.

List all repositories (effectively images):

curl -X GET -u admin:admin https://myregistry:5000/v2/_catalog
> {"repositories":["redis","ubuntu"]}

List all tags for a repository:

curl -X GET admin:admin https://myregistry:5000/v2/ubuntu/tags/list
> {"name":"ubuntu","tags":["14.04"]}

--

--