Introduction:

The Registry is a stateless, highly scalable server-side application that stores and lets you distribute Docker images. The Registry is open-source, under the permissive Apache license.

Why use it

You should use the Registry if you want to:

  • tightly control where your images are being stored
  • fully own your images distribution pipeline
  • integrate image storage and distribution tightly into your in-house development workflow ReadMore

Requirements

The Registry is compatible with Docker engine version 1.6.0 or higher.

Type below command in your terminal to find your version.

docker --version
Docker version 20.10.6, build 370c289

Now create a docker-compose file and pas the below code

version‘3.7’

services:
    registry:
        container_nameregistry
        restartalways
        imageregistry:2
        ports:
            – 5000:5000
        environment:
            REGISTRY_AUTHhtpasswd
            REGISTRY_AUTH_HTPASSWD_PATH/auth/htpasswd            
            REGISTRY_AUTH_HTPASSWD_REALMRegistry Realm  
        volumes:
            – .:/var/lib/registry
            – .:/auth
docker-registry

run the below code in your terminal to create htpassed file, don’t forget to change the username and password

docker run \
    –entrypoint htpasswd \
    httpd:2 -Bbn admin admin > htpasswd
docker-registry

You have your htpasswd file which stores your username and password in bcrypt type

It is time to bring up our container 

docker-compose up -d

docker-registry

Now login to your private registry

docker login localhost:5000

username: admin

password: admin

docker-registry
Pull (or build) some image from the hub

docker pull ubuntu

Tag the image so that it points to your registry

docker image tag ubuntu localhost:5000/myfirstimage

Push it

docker push localhost:5000/myfirstimage

Pull it back

docker pull localhost:5000/myfirstimage

check how many images do we have in registry, past in your browser
localhost:5000/v2/_catalog

to check your repository inside registry

docker exec -it registry sh

cd /var/lib/registry/docker/registry/v2/repositories

Now stop your registry and remove all data

docker container stop registry && docker container rm -v registry

Conclusion:

We have learned how to deploy a private docker registry with a username and password

Key Point:

Creat private registry

Log in to the private registry

push image

pull image