Docker Private Registery

 Docker private registry

Why we need pvt registry

"Security, minimize internet load, speed, control

We need to setup registry in three stage , stage one  simple stage two  secure (with ssl)

 stage three with authentication

Stage one:

Step: create directories, need to create below directories

a. Create a directory to store docker image

b. create a certificate directory

c. Auth directory

Step :Run a docker registry container

Create a container without volume with below command

sudo  docker run -d -p 5000:5000 --name local-registry registry:2

below is screen shot

check in browser:




 tag the image, command to tag image

sudo docker tag centos:7 127.0.0.1:5000/centos:7

Step Push image and check the browser again

In ss centos is available, also in container it show as below 


Stage two

Step:  create a directory with the name of "docker-registry" then create two direcotries inside it 

certs  data

Step: then generate certificate inside certs directory

first generate CSR and KEY:

sudo openssl req -new -newkey rsa:4096 -nodes -keyout ab.example.com.key -out ab.example.com.csr

then generate PEM and self-sign with KEY:

sudo openssl x509 -req -sha256 -days 365 -in ab.example.com.csr -signkey ab.example.com.key -out ab.example.com.pem

After installing certificate  we have three file in cert directory

ab.example.com.csr  ab.example.com.key  ab.example.com.pem

Step: Then create a directory inside the /etc/docker/cert.d/

inside this directory create a directory with the name of "ab.example.com:443" I choose this name as my hostname you can choose as per required registry name

Step: Copy certificate inside this with ca.cert extension

Step: add entry in /etc/hosts file

Step: then stop the old running registry container and restart docker service

Step: create new one with secure registry, I have created with below script:

--------------


docker run -d \

  --restart=always \

  --name registry \

  -v ./data:/var/lib/registry \

  -v ./certs:/certs \

  -e REGISTRY_HTTP_ADDR=0.0.0.0:443 \

  -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/ab.example.com.pem\

  -e REGISTRY_HTTP_TLS_KEY=/certs/ab.example.com.key \

  -p 443:443 \

  registry:2

-------------------------------

Step: then tag image with below command:

ab@ab:~/Desktop/ab_lvm/docker-registry$ sudo docker tag nginx:latest ab.example.com:443/nginx:latest

Step: then push the image

ab@ab:~/Desktop/ab_lvm/docker-registry$ sudo docker push ab.example.com:443/nginx:latest


image pushed successfully

I can check inside the container , as below 




Stage three

Comments

Popular posts from this blog