ഇതൊഴിവാക്കി പ്രധാന ഉള്ളടക്കത്തിലേക്ക് പോവുക

How to create a local docker images repository?





Prerequisites

1. Docker and docker-compose.

        > apt-get install docker

        > apt-get install docker-compose

    In Centos, 

    yum install docker-compose

    > yum install docker-compose

2. Nginx , 

    command: apt-get install nginx.

    In Centos,

      >yum install nginx

3. Self -Signed SSL certificate for Nginx.

4. apache2-utils to restrict image access using user name and password.

    command: apt-get install apache2-utils

    In Centos,

        > yum install httpd-tools

5. Nano editor (you can use any editor you like).

Command: apt-get install nano

In Centos,

  > yum install nano

Let's Begin,

 

First, we need to create a docker-registry to keep images and authentication data.

 

1. Let's create a docker-registry directory and data,auth directories inside root.

 

> mkdir ~/docker-registry && cd $_

> mkdir data

> mkdir auth


Now create a docker-compose.yml file and add the following content

//Creating a docker-compose.yml file

> nano docker-compose.yml

 

//docker-compose content

version: '3'

 

services:

  docker-registry:

    image: registry:2

restart: always

container_name:  docker-registry

    ports:

    - "5000:5000"

    environment:

      REGISTRY_AUTH: htpasswd

      REGISTRY_AUTH_HTPASSWD_REALM: Registry

      REGISTRY_AUTH_HTPASSWD_PATH: /auth/registry.password

      REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data

    volumes:

      - ./auth:/auth

      - ./data:/data

 

  docker-registry-ui:

    image: konradkleine/docker-registry-frontend:v2

    container_name: docker-registry-ui

    ports:

      - "8080:80"

    environment:

      ENV_DOCKER_REGISTRY_HOST: docker-registry

      ENV_DOCKER_REGISTRY_PORT: 5000

 

//Before running docker-compose up,lets create a user for docker login purpose


> cd auth

> htpasswd -Bc registry.password <username>

 

Example:


> htpasswd -Bc registry.password advik

And then enter password

 

 

//Check authentication working by running docker-compose


> docker-compose up -d

 

//and then go to http://localhost:5000/v2 

// After entering username and the corresponding password, you  will see {} again

// Now we can set up nginx

// let's create an open SSL certificate for nginx

> openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt


//Enter current system’s IP address as Common Name in the certificate

//Configuring Nginx to Use SSL

 

>  sudo nano /etc/nginx/snippets/self-signed.conf


//self-sgned.conf content

 

ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;

ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

 

//add SSL certificate info to advik-images.com

 

> sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/advik-images.com

 

> sudo nano /etc/nginx/sites-available/advik-images.com

 

//advik-images.com - Content

      server

{

listen 443 SSL;

 listen [::]:443 SSL; 

include snippets/self-signed.conf;       

server_name advik-images.com www.advik-images.com; 

 root /var/www/advik-images.com/html;

location / {                                                                                                         

        proxy_pass    http://localhost:5000;                

proxy_set_header  Host    $http_host; 

proxy_set_header  X-Real-IP         $remote_addr; # pass on real client's IP 

proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;   

proxy_set_header  X-Forwarded-Proto $scheme;

proxy_read_timeout    900; 

}

}

server {

listen 80;

  listen [::]:80;

root /var/www/advik-images.com/html; 

index index.html index.htm index.nginx-debian.html; 

server_name advik_images.com www.advik-images.com;

return 301 https://$server_name$request_uri;

}

 

//Create advik-images.com index page


>  sudo mkdir -p /var/www/advik-images.com/html   

>  sudo chown -R $USER:$USER /var/www/advik-images.com/html

>  sudo chmod -R 755 /var/www/advik-images.com

>  nano /var/www/advik-images.com/html/index.html

 

//index.html content

<html>

    <head>

        <title>Welcome to Advik-Images.com!</title>

    </head>

    <body>

        <h1>Success!  The Advik-Images.com server block is working!</h1>

    </body>

</html>


//Create a soft link of advik-images.com to site-enabled


> sudo ln -s /etc/nginx/sites-available/advik-images.com /etc/nginx/sites-enabled/

 

// To avoid a possible hash bucket memory problem


> sudo nano /etc/nginx/nginx.conf

 

//add these lines to Nginx.conf

“ server_names_hash_bucket_size 64; “

“ client_max_body_size 2000M; “

Example :

 

http {

    ...

    server_names_hash_bucket_size 64;

client_max_body_size 2000M;

    ...

}


//Ok let's configure the firewall to allow only HTTP and HTTPS

> sudo ufw allow "Nginx HTTP"


 

//stop and start Nginx

 

> service stop Nginx

> service start nginx

 

 

// Let's add exception inside docker to allow login from the current system.

//If you want to login into docker add an exception for docker in that system by giving this system’s IP as an exception.

//for that let's create daemon.json and add a JSON document inside etc/docker directory.

 

//Here My System’s IP is 192.168.2.14.

(here I added advik-images.com also, so that later we can pull using both IP and domain name)

 

> nano /etc/docker/daemon.json

 

//daemon.json content

Example :

{

"insecure-registries":["192.168.2.14","advik-images.com"]

}

 *(here I added advik-images.com also, so that later we can pull using both ip and domain name)

//now stop and start docker service

 

> service docker stop

> service docker start


//Lets add advik.images.com to /etc/hosts also,so that it will redirect to the ip

 > nano /etc/hosts

//etc/hosts content

Example :

...
192.168.2.14    advik-images.com
...

// let's publish an image into docker-repository

//For that, I am pulling a small image alpine from docker hub first

 

> docker pull alpine

 

// let's tag it with repository address specified to create an image to push into the repository.

Syntax : docker tag <image full name> <ip>/<username>/new image full name.

Example:

 

> docker tag alpine:latest 192.168.2.14/akhi/test-image:v1

 

//login to docker repository to push the image

Example:

 

> docker login 192.168.2.14

//enter user name and password

 

//the push image

Example:

 

> docker push 192.168.2.14/akhi/test-image:v1

 

 

// Now Try to pull that image back.

//First login

 

> docker login 192.168.2.14

//enter user name and password

 

//Then pull the image by giving address and image name

Example:

 

> docker pull 192.168.2.14/akhi/test-image:v1

 

(Similarly, you can use docker login advik-images.com also )


Thank You


References:

https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-16-04

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-private-docker-registry-on-ubuntu-18-04

https://www.youtube.com/watch?v=8gEs_zefNYA

Host your own docker registry | Local Docker Registry | Docker Registry using Docker Compose | SelfTuts Channel

 

അഭിപ്രായങ്ങള്‍

ഈ ബ്ലോഗിൽ നിന്നുള്ള ജനപ്രിയ പോസ്റ്റുകള്‍‌

തിരിച്ചറിവ്

{ഞാനും നീയും എന്ന എന്റെ സുഹൃത്ത്‌ പി.വി.ജോണിന്റെ പോസ്റ്റിനു കമന്റ്‌ ആയി എഴുതിയത് } ഞാനും നീയും ഒരൊറ്റ മനസ്സായിരുന്നപ്പോഴും ഒരു ശരീരമായിരുന്നപ്പോഴും ഓര്‍ത്തിരുന്നില്ല  രണ്ടു വ്യത്യസ്ത വാക്കുകള്‍ ആണെന്ന്...  

നുറുങ്ങുകള്‍ തീര്‍ക്കുന്നു നുറുങ്ങുവെട്ടം....

നുറുങ്ങുകള്‍ തീര്‍ക്കുന്നു നുറുങ്ങുവെട്ടം.... ( ഈ പോസ്റ്റ്‌ എഴുതാന്‍ പ്രചോദനമായ  ഹൈക്കു പോയംസ്  https://www.facebook.com/groups/Haikupoems/   എന്ന ഗ്രൂപ്പിനും  എന്നെ എന്നും പ്രോല്‍സാഹിപ്പിച്ചു കൊണ്ടിരിക്കുന്ന  https://www.facebook.com/groups/malayalamblogers/    മലയാളം ബ്ലോഗേഴ്സ് ഗ്രൂപ്പിനും    ഒത്തിരി നന്ദി..  ഒപ്പം വേണുഗോപാല്‍ ഏട്ടന്‍, തമ്പാന്‍ നായര്‍..,  സോണി ചേച്ചി,ഗിരിജ ചേച്ചി, ശിവപ്രസാദ്‌ പാലോട്‌, അപ്പു എം ശിവന്‍,സുമയ്യ തന്നാരി,  പ്രിയ കളരിക്കല്‍, പ്രിയക്കുട്ടി  അനീഷ്‌ കെ.വി,ഷാജു ഏട്ടന്‍  എന്നിവര്‍ക്കും നിങ്ങള്‍ക്കും   ഒത്തിരിയൊത്തിരി നന്ദി )  വായനക്കാരെ നിങ്ങള് സഹിച്ചോളീന്‍.....,..............       ലൈക്കുന്നു ചിലര്‍              പോക്കുന്നു ചിലര്‍       ചിരിക്കുന്നു ചിലര്‍          മനസ്സുകള്‍ തമ്മില്‍       കുറയുന്നു വിള്ളല്‍       കൊഴിയുന്ന മോഹം       കരിയുന്ന സ്വപ്നം          ഞാന്‍ വെറും കരിയില       ആശകള്‍ വേണ്ട       കാശുകള്‍ മതി       വാശിയില്‍ ഓടി       അന്ത്യ നേരം       മൂശയില്‍ കോറി       നിരാശകള

അതിരപ്പിള്ളിയും കടന്നൊരു വെള്ള-ച്ചാട്ടം - ഭാഗം1

"എബ്ടെക്കാ കാലത്തെന്നെ ഇത്രേ നേരത്തെ!" "ഏയ്‌..ഒന്നൂല്യച്ചാ ഈ അതിരപ്പിള്ളി വരെ.." "ആരാടാ കൂടെ " (അലംബ് ടീംസ് ആണോന്ന്.. ) "കോളേജിലെ കുട്ട്യോളാ അച്ഛാ.. വീക്കെന്‍ഡല്ലേ.. കോഴിക്കോട് പാര്‍ട്ടീസാ .. അവരീന്തിരപ്പിള്ളി കണ്ടട്ടില്ലേയ്.പിന്നെ ആ പുതുക്കാട് ജോസെനും ഉണ്ട്.    ഇന്നാളു കണ്ടില്ലെച്ചന്‍, അവന്‍" അവന്റെ പേര് പറഞ്ഞോണ്ട് ആണോന്നറിയില്ല..പക്ഷെ പിന്നെ കേട്ടത് " ഒരച്ഛന്റെ രോദനം " ആയിരുന്നു . "ഇന്നാളു പോയില്ലേ നീയ്‌.പിന്നെ എന്തിനാ വീണ്ടും.  ങ്ഹാ.. പിള്ളേര് സെറ്റാവുമ്പോ, ആവേശം കൂടുമ്പോ ഒരു വെള്ള ചാട്ടം ഉണ്ടാവും. അച്ഛനെ കുട്ടിയ്ക്ക് അങ്ങനെ ഒരു വെള്ളച്ചാട്ടം വേണ്ടാട്ടാ.." ആ സ്നേഹപ്രകടനത്തില്‍ ഞാന്‍ അലിഞ്ഞു പോവുമെന്ന് അച്ഛന്‍ വിചാരിച്ചു കാണും.   എന്നാലും പ്രലോഭനങ്ങളില്‍ വീഴാതിരിക്കുക എന്നത് യുവാക്കളുടെ കര്‍ത്തവ്യം ആണല്ലോ. "ആ പിന്നെ..അച്ഛാ ആ പഴയ ക്യാമറ.." "എടുത്തോ..പിന്നെ ആര്‍ക്കും കൊടുക്കരുത്‌ ..പിന്നെ ഫോടോന്റെ ഫങ്ങി നോക്കലോക്കെ അവസാനം മതി.ബാറ്ററി എങ്ങാനും തീര്‍