Home » Creating Private Docker Registry

Creating Private Docker Registry

Prerequisites

  • VM that will act as the registry server
  • VM that will act as a client

 These VMs will have Ubuntu 20.04 installed

Install Docker

Install Docker on Server and Client

# Update existing packages list
$ sudo apt update

# Install packages required for HTTPS apt packages
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common

# Add the GPG key for the official Docker repository and docker repository
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
$ apt-cache policy docker-ce

# Install docker
$ sudo apt install docker-ce
$ sudo systemctl status docker

Executing the Docker Command Without Sudo

# add a user ($USER) to the docker group
$ sudo usermod -aG docker ${USER}
$ su - ${USER}
$ groups

# Using the Docker Command
$ docker [option] [command] [arguments]
$ docker


Working with Docker images

# Verify if you can access Docker Hub
$ docker run hello-world

# Sample output
Output
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.


# Search images availble in the Docker Hub
$ docker search ubuntu

# Downloading an images
$ docker pull ubuntu

# See available images
$ docker images

Running a Docker image

# The combination of the -i and -t switches gives you interactive shell access into the container:
$ docker run -it ubuntu

# Command prompt that indicate you are inside the container

# Output
root@d8b600b2f738:/#

Managing Docker Container

# View Active Containers
$ docker ps

# View active and inactive Containers
$ docker ps -a

# View latest Container created
$ docker ps -l

# Start a Container
$ docker start <image id>

# Remove container using name
docker rm <container name>

# Committing changes
docker commit -m "commit message or description" -a "Author Name" container_id repository/new_image_name

Create Self-Signed Certificate

$ openssl req  -newkey rsa:4096 -nodes -sha256 -keyout domain.key -x509 -days 365 -out domain.crt
$ sudo mkdir -p /etc/docker/certs.d/192.168.1.109:5000
$ sudo cp domain.crt /etc/docker/certs.d/192.168.1.109:5000/ca.crt
$ sudo cp domain.crt /usr/local/share/ca-certificates/ca.crt
$ sudo update-ca-certificates
$ sudo systemctl stop docker
$ sudo systemctl start docker

Installing Nginx

# Nginx packages
sudo apt update
sudo apt install nginx

#verify nginx serivce
systemctl status nginx

# test web service, replace the "your_server_ip with the address of your nginx server"
http://your_server_ip

  * You should receive the default Nginx landing page
  
 

Installing and configuring Docker Registry using Docker Compose

# pwd
/home/subok/

# create docker directory
$ mkdir ~/docker-reg
$ cd ~/docker-reg
$ mkdir data

# create docker compose yaml file
$ nano docker-compose.yml

*****************  docker-compose.yml  *******
version: '3'

services:
  registry:
    image: registry:2
    ports:
    - "5000:5000"
    environment:
      REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data
    volumes:
      - ./data:/data
*********************************************

$ docker-compose up

Committing Changes and Pushing containers to Registry

# Committing Changes to Images
# docker commit -m "note change" -a "Author" container_id image_name
# e.g.
$ docker cf2114087f2d subokf5gc-nrf
$ docker tag subokf5gc-nrf subok-docker-registry:5000/subokf5gc-nrf

# Pushing Images to Registry
$ docker push subok-docker-registry:5000/subokf5gc-nrf

Leave a Reply

Your email address will not be published. Required fields are marked *