- 2 mins

Creating Your Own Private Docker Registry

Table of Contents

0. Prerequisites

1. Creating a directory to store registry data

$ mkdir -p /Users/Topaz/opt/docker/registry/data

2. Creating a self-signed SSL certificate for the registry

 // Step 1: Createing a directory to store certificate
 $ mkdir -p /Users/Topaz/opt/docker/registry/certs

 // Step 2: Creating a self-signed SSL certificate
  openssl req -newkey rsa:4096 -nodes -sha256 -keyout /Users/Topaz/opt/docker/registry/certs/domain.key -x509 -days 365 -out /Users/Topaz/opt/docker/registry/certs/domain.crt

3. Setting up a Docker Registry Service with Docker Compose

1.Create a directory to store docker-compose.yml for easy to maintenance

 $ mkdir -p /Users/Topaz/Projects/DockerRegistry

2.Create a Docker Compose file to define your registry service.

 $ cd /Users/Topaz/Projects/DockerRegistry

 $ vim docker-compose.yml
 version: '3'
 services:
   registry:
     image: registry:2
     ports:
       - "5000:5000"
     environment:
       REGISTRY_AUTH: htpasswd
       REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
       REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
       REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
       REGISTRY_HTTP_TLS_KEY: /certs/domain.key
     volumes:
       - ./htpasswd:/auth/htpasswd
       - ./registry:/var/lib/registry
       - /Users/Topaz/opt/docker/registry/data:/var/lib/registry/data
       - /Users/Topaz/opt/docker/registry/certs:/certs
  1. Start registry service using the following command:
 $ docker-compose up -d

4. Managing Docker Images in Your Private Registry

  1. Create username and password for your registry
 // Checking you are under correct path
 $ pwd
 /Users/Topaz/Projects/DockerRegistry

  // Creating directory to store your username and password
 $ mkdir registry

 // Create password
 $ docker run --rm --entrypoint \
     htpasswd httpd:2 -Bbn \
     admin 12345678 > ./registry/htpasswd

List the images that exist on the your Docker registry

 $ docker search localhost:5000
Topaz

Topaz

Always keep learning.

comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium vimeo