Set up Docker Registry locally on CentOS 7

Introduction

I have a lot of images on DockerHub, but I've wanted to download and launch my own Docker image in my Registry at any time.

You can prepare a Dockerfile and create it from the Docker image downloaded from DockerHub, but it takes a surprising amount of time, so I'd like to prepare an image in a ready state and put it on some Docker server.

Communication with certificate registration via HTTPS is also possible, but this is just a method of preparing an environment that can be used quickly for internal use.

Have two environments (such as VMs) on the server and client.

procedure

Roughly the following steps

Install Docker

Must be installed on the Redistry server and client side. Download destination registration is required to install docker to rpm.

yum -y install yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce

Start Docker

Start the docker service on the Redistry server and client side, and start it automatically when the OS starts.

systemctl start docker
systemctl enable docker

Preparing Docker Registry

Download the Registry image on the Registry server

docker pull registry

Docker image is added as below

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
registry            latest              2d4f4b5309b1        3 months ago        26.2MB

Launch Docker Registry

Start Docker Registry. At this time, since we want to make the image on the Registry persistent, mount the directory of the host OS in the container.

docker run -d -p 5000:5000 \
	-v /var/opt:/var/lib/registry \
	registry

Confirm that the container has started

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
35b3882b8536        registry            "/entrypoint.sh /etc…"   About an hour ago   Up About an hour    0.0.0.0:5000->5000/tcp   dreamy_roentgen

The following directory is created in the host OS and mounted under this directory.

ls /var/opt/docker/registry/v2/
blobs  repositories

When the image is registered, it is the directory where the image is saved under repositories as shown below.

ls -l /var/opt/docker/registry/v2/repositories/aaa
Total 0
drwxr-xr-x 5 root root 55 September 16 15:33 centos_local

Image preparation on the server side (download and Registry)

Download the original image to register with the local Repository server

Anything is fine, but download CentOS for the time being

docker pull centos
Using default tag: latest
latest: Pulling from library/centos
3c72a8ed6814: Pull complete
Digest: sha256:76d24f3ba3317fa945743bb3746fbaf3a0b752f10b10376960de01da70685fbd

Confirm that it was downloaded

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              0d120b6ccaa8        5 weeks ago         215MB
registry            latest              2d4f4b5309b1        2 months ago        26.2MB

Create (tag) image to register with docker Registry

Originally, I used Dockerfile etc. to create an image with various tools and settings, but this time I simply use the downloaded CentOS image as it is

docker tag centos localhost:5000/aaa/centos_local:1.0

If you tag it, you can create an image like the one below.

docker images
REPOSITORY                          TAG                 IMAGE ID            CREATED             SIZE
centos                              latest              0d120b6ccaa8        5 weeks ago         215MB
localhost:5000/aaa/centos_local   1.0                 0d120b6ccaa8        5 weeks ago         215MB
registry                            latest              2d4f4b5309b1        2 months ago        26.2MB

Register image in docker Registry

Register tagged images in docker Registry

docker push localhost:5000/aaa/centos_local:1.0
The push refers to repository [localhost:5000/iseki/centos_local]
291f6e44771a: Pushed
1.0: digest: sha256:fc4a234b91cc4b542bac8a6ad23b2ddcee60ae68fc4dbd4a52efb5f1b0baad71 size: 529

After registration, the image is no longer needed and will be deleted

docker rmi localhost:5000/iseki/centos_local:1.0
Untagged: localhost:5000/iseki/centos_local:1.0
Untagged: localhost:5000/iseki/centos_local@sha256:fc4a234b91cc4b542bac8a6ad23b2ddcee60ae68fc4dbd4a52efb5f1b0baad71

After deleting, check that there are no images in the list

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              0d120b6ccaa8        5 weeks ago         215MB
registry            latest              2d4f4b5309b1        2 months ago        26.2MB

Download images from Docker Registry

Download on the server side

You can download it from the server by executing the following command

docker pull localhost:5000/aaa/centos_local:1.0

Download on the client side

From the client side, you cannot connect unless you enter the following settings in the "client side"

cat /etc/docker/daemon.json
{ "insecure-registries":["<Docker Registry server IP or host name>:5000"] }

Make the above settings and restart the docker service

systemctl restart docker

In this state, execute the command to get the image from the docker Registroy server.

docker pull 10.1.5.25:5000/aaa/centos_local:1.0
1.0: Pulling from iseki/centos_local
3c72a8ed6814: Pull complete
Digest: sha256:fc4a234b91cc4b542bac8a6ad23b2ddcee60ae68fc4dbd4a52efb5f1b0baad71
Status: Downloaded newer image for 10.1.5.25:5000/aaa/centos_local:1.0
10.1.5.25:5000/aaa/centos_local:1.0

docker image is downloaded

# docker images
REPOSITORY                          TAG                 IMAGE ID            CREATED             SIZE
10.1.5.25:5000/aaa/centos_local   1.0                 0d120b6ccaa8        7 weeks ago         215MB

Recommended Posts

Set up Docker Registry locally on CentOS 7
Set up ImpressPages 5.0 with LAMP on CentOS 7.3
Docker installation on CentOS 6
Set up GitLab with docker
Steps to set up a VNC server on CentOS 8.3
Set up ansible-playbook on Ubuntu 20.04
WordPress with Docker Compose on CentOS 8
Use Docker CE (official) on CentOS 8
Install Docker on Ubuntu and set up remote connection using tls
Publish Docker Image on GitHub Package Registry
Set up Metabase service on Windows Server 2012
Liberty on Docker
Gachi beginners set up containers on Kubernetes? Until···
Set up an SSH server on WSL2 Ubuntu 20.04
OpenVPN on CentOS 8
Set up a CentOS virtual server with Vagrant
Redmine on Docker
I want to hit the API with Rails on multiple docker-composes set up locally
Maven on CentOS 7 tutorial
Use perltidy on CentOS 8
Install Golang on CentOS 8
Try OpenLiteSpeed on CentOS8
python notes on docker
Install Neo4j 4.1.3 on centOS
Tomcat v8 on CentOS7
Install Docker on Manjaro
Install Vertica 10.0 on CentOS 6.10
Zabbix 5 installation on CentOS 8
Use mod_auth_cas on CentOS 8
Install nginx on centOS7
Install Python 3 on CentOS 7
Install kuromoji on CentOS7
Use bat on Centos.
Jetty v8 on CentOS7
Install Mattermost on CentOS 7
Install PostGIS 2.5.5 on CentOS7
Install jpndistrict on CentOS 7
M.S. docker on Windows
Install Redmine 4.1.1 on CentOS 7
Smokeping Install on CentOS7
Install PostgreSQL 13 on CentOS 7.5
Docker installation on WSL2
Run phpunit on Docker
Until you start nginx on CentOS using Docker on Mac OS
A story about speeding up unittest on Docker for Mac
Set up a MineCraft Paper server on Ubuntu 20.04.1 LTS ② Update
Set up Django on Ubuntu 16.04 with PostgreSQL and Gunicorn on ECS