Wednesday, October 28, 2026
HomeCloud Computingdeploy a self-hosted Docker registry with self-signed certificates

deploy a self-hosted Docker registry with self-signed certificates

[ad_1]

docker-with-waves.jpg
Illustration: Lisa Hornung/TechRepublic

If you want a Docker registry hosted in your LAN and also you don’t wish to undergo the difficulty of buying certificates from a Certificates Authority, what do you do? You deploy a registry utilizing self-signed certificates.

SEE: Hiring Equipment: JavaScript Developer (TechRepublic Premium)

Though that course of is a little more difficult, it’s not so difficult that any IT admin can’t pull it off.

And I’m going to point out you simply the way to do it.

What you’ll want

To make this work, you’ll want no less than two machines, each of which have Docker put in. I’m going to display on Ubuntu Server 20.04 and Pop!_OS desktop. If you happen to’re utilizing a distinct working system, you’ll want to change the method accordingly.

create your directories

The very first thing we’re going to do is create some directories to deal with the repository and the mandatory certificates. I’m going to display this on my customers’ residence listing, however you’ll be able to place them in any listing to which your consumer has entry.

Create the bottom listing with:

mkdir ~/registry

Create the 2 subdirectories with:

mkdir ~/registry/certs

mkdir ~/registry/auth

Change within the certs listing with:

cd ~/registry/certs

Generate a personal key with:

openssl genrsa 1024 > area.key

Change the permissions for the brand new key with:

chmod 400 area.key

Subsequent, we have to generate our certificates. Nonetheless, due to the best way the authorization course of now works, we should first create a san.cnf file with:

nano san.cnf

In that file, paste the next contents (ensuring to edit accordingly):

[req]

default_bits  = 2048

distinguished_name = req_distinguished_name

req_extensions = req_ext

x509_extensions = v3_req

immediate = no

[req_distinguished_name]

countryName = XX

stateOrProvinceName = N/A

localityName = N/A

organizationName = Self-signed certificates

commonName = 120.0.0.1: Self-signed certificates

[req_ext]

subjectAltName = @alt_names

[v3_req]

subjectAltName = @alt_names

[alt_names]

IP.1 = 192.168.1.191

Ensure that to alter (no less than) IP.1 = to match the IP handle of your internet hosting server.

Save and shut the file.

Generate the important thing with:

openssl req -new -x509 -nodes -sha1 -days 365 -key area.key -out area.crt -config san.cnf

Become the auth listing with:

cd ../auth

We now should pull down the registry container and have it generate an htpasswd file. That is executed with the command:

docker run --rm --entrypoint htpasswd registry:2.7.0 -Bbn USERNAME PASSWORD > htpasswd

The place USERNAME is a novel username and PASSWORD is a novel/sturdy password.

deploy the registry server

It’s now time to deploy the registry server. Change again to the bottom registry listing with:

cd ~/registry

Deploy the registry container with the command:

docker run -d

--restart=all the time

--name registry

-v `pwd`/auth:/auth

-v `pwd`/certs:/certs

-v `pwd`/certs:/certs

-e REGISTRY_AUTH=htpasswd

-e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm"

-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd

-e REGISTRY_HTTP_ADDR=0.0.0.0:443

-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/area.crt

-e REGISTRY_HTTP_TLS_KEY=/certs/area.key

-p 443:443

registry:2.7.0

Your registry ought to now be working and accessible from the native machine. If, nonetheless, you wish to entry it from a distant system, we have to add a ca.crt file. You’ll want to copy the contents of the ~/registry/certs/area.crt file.

Log into your second machine and create a brand new listing with:

sudo mkdir -p /and so forth/docker/certs.d/SERVER:443

The place SERVER is the IP handle of the machine internet hosting the registry.

Create the brand new file with:

sudo nano /and so forth/docker/certs.d/SERVER:443/ca.crt

The place SERVER is the IP handle of the machine internet hosting the registry.

Paste the contents from the area.crt file (from the internet hosting server) into this new file. Save and shut the file.

login to the brand new registry

From the second machine, open a terminal window and log into your new Docker registry with the command:

docker login -u USER -p https://SERVER:443

The place USER is the consumer you added whenever you generated the htpasswd file above and SERVER is the IP handle of the machine internet hosting the registry.

You ought to be prompted for a password. Upon profitable authentication, you’ll see Login Succeeded.

Congratulations, you’re now ready to make use of that self-hosted Docker registry to your container pictures.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the newest tech recommendation for enterprise execs from Jack Wallen.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments