← Start of tutorial

WIUNIX ACADEMY

Private Docker registry with Nginx HTTPS and native authentication

Page 3 of 5. Review the earlier steps and prerequisites before continuing.

YOUR SYSTEM. YOUR STEPS.

Where are you working?

Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.

Ubuntu 24.04 LTSReviewed against official documentation ·

USE YOUR OWN VALUES

Configure this tutorial

Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.

Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.

Set values for my environment8 editable values
08

LET’S BUILD

Place the existing trusted certificate securely

Use your approved root-only transfer/editor procedure to place the existing fullchain and unencrypted service private key in the two files below; never paste them in browser settings. Require root ownership, real regular files, private key0600, TLS directory0700 and fullchain0644. Do not generate a self-signed public certificate as a workaround. No public CA account or issuance is performed by this guide.

bash

Registry VM

sudo python3 - <<'PY'
import os
for name in ('fullchain.pem','privkey.pem'):
    f='/srv/academy-registry/tls/'+name
    fd=os.open(f,os.O_WRONLY|os.O_CREAT|os.O_EXCL|os.O_NOFOLLOW,0o600)
    os.close(fd)
PY
sudo nano '/srv/academy-registry/tls/fullchain.pem' '/srv/academy-registry/tls/privkey.pem'
sudo chmod 0644 '/srv/academy-registry/tls/fullchain.pem'
How do I know it worked?

Existing trusted chain and matching key are saved privately; neither remains an empty placeholder.

09

LET’S BUILD

Check hostname, expiry and key match

Run on the VM before enabling HTTPS. The checks establish SAN match, at least seven days remaining and public-key equality; they do not establish full-chain trust from every client. Verify full-chain trust from a clean managed client in the HTTPS check below. Renewal must validate the new chain/key, run Nginx syntax validation, reload and check the actually served certificate.

bash

Registry VM

sudo openssl x509 -in '/srv/academy-registry/tls/fullchain.pem' -noout -checkhost 'registry.example.net'
sudo openssl x509 -in '/srv/academy-registry/tls/fullchain.pem' -noout -checkend 604800
sudo python3 - <<'PY'
import subprocess
base='/srv/academy-registry/tls/'
a=subprocess.check_output(['openssl','x509','-in',base+'fullchain.pem','-pubkey','-noout'])
b=subprocess.check_output(['openssl','pkey','-in',base+'privkey.pem','-pubout'])
assert a==b, 'Certificate and private key do not match'
print('Public-key match: OK')
PY
How do I know it worked?

Hostname/expiry checks succeed and public keys match.

10

LET’S BUILD

Review firewall, SELinux and the Nginx include

The public listener is Nginx TCP443; 5000 stays loopback-only. Review the active host and upstream firewall policy, preserve SSH and open only HTTPS to intended client networks. Do not enable a second firewall manager or flush Docker/nftables rules. Ubuntu may use UFW, RPM commonly uses firewalld, and Arch/Manjaro may use an existing nftables policy; distribution labels do not identify the policy actually running. The firewall-inspection commands are read-only; selected SELinux/include setup follows them in the same panel.

RPM variants additionally label only the dedicated TLS/parent paths and allow Nginx network connections through SELinux; they record the previous boolean first. Container data/auth/config were labeled separately by Docker. Arch/Manjaro variants back up nginx.conf, open it for the HTTP include, then validate syntax before any reload. Review rule/log output privately.

bash

Registry VM

set -eu
. /etc/os-release
printf 'Selected host: %s %s\n' "$ID" "$VERSION_ID"
if command -v ufw >/dev/null; then sudo ufw status verbose; fi
if command -v firewall-cmd >/dev/null; then sudo firewall-cmd --get-active-zones; fi
if command -v nft >/dev/null; then sudo nft list ruleset; fi
sudo ss -lntp
How do I know it worked?

Actual host policy/listeners are reviewed; the selected SELinux/include prerequisites are prepared without weakening authentication.

Arch/Manjaro HTTP include

Only Arch/Manjaro without this include: insert this line inside the existing http block, preserving the rest of the package configuration. Other paths normally already load conf.d; do not duplicate it.

nginx · /etc/nginx/nginx.conf

Registry VM

include /etc/nginx/conf.d/*.conf;
11

LET’S BUILD

Load the site in Nginx and start or reload safely

The site must be loaded inside the HTTP context, not merely present in conf.d. Debian/Ubuntu and RPM normally provide the include; Arch/Manjaro receive a separately reviewed include step. The new site filename must not already exist. A syntax/include failure moves only this new file into recovery and leaves running configuration untouched.

After syntax and effective-file verification, enable nginx, reload an active service or start an inactive one. Open host TCP443 only through your approved network policy once TLS is ready; never open the loopback backend port. A healthy unauthenticated endpoint returns401, a Basic challenge and registry/2.0 API header. A200 without credentials is a security failure. Do not redirect /v2/ to browser SSO.

bash

Registry VM

set -eu
sudo install -d -m 0755 /etc/nginx/conf.d /var/log/nginx
sudo test ! -e '/etc/nginx/conf.d/academy-registry.conf'
sudo test ! -L '/etc/nginx/conf.d/academy-registry.conf'
sudo python3 - <<'PY'
import os,stat
from pathlib import Path
src=Path('/srv/academy-registry/config/nginx.conf')
assert stat.S_ISREG(src.lstat().st_mode) and src.stat().st_uid==0
fd=os.open('/etc/nginx/conf.d/academy-registry.conf',os.O_WRONLY|os.O_CREAT|os.O_EXCL|os.O_NOFOLLOW,0o644)
with os.fdopen(fd,'wb') as out: out.write(src.read_bytes())
os.chmod('/etc/nginx/conf.d/academy-registry.conf',0o644)
PY
if sudo nginx -t && sudo nginx -T 2>&1 | grep -F "# configuration file /etc/nginx/conf.d/academy-registry.conf:"; then
  sudo systemctl enable nginx
  if sudo systemctl is-active --quiet nginx; then sudo systemctl reload nginx; else sudo systemctl start nginx; fi
else
  sudo mv '/etc/nginx/conf.d/academy-registry.conf' '/srv/academy-registry/recovery/failed-nginx.conf'
  exit 1
fi
curl --silent --show-error --dump-header - --output /dev/null 'https://registry.example.net/v2/'
How do I know it worked?

Syntax and effective include checks pass; active service reloads or inactive service starts; trusted HTTPS returns401.

12

LET’S BUILD

Use a credential helper for Docker login

Run on a Linux client as its normal user, not on the registry VM as root. Initialize pass/GPG and install the official helper using its owning documentation first. This command creates a fresh isolated Docker client configuration containing only helper routing. Docker prompts privately for the password; do not use a password option or an environment dump. Failures must be fixed in the helper/trust setup, never by removing the helper and accepting plaintext JSON credentials.

bash

Linux client

set -eu
command -v docker-credential-pass
pass ls >/dev/null
python3 - <<'PY'
import json, os
from pathlib import Path
p=Path.home()/'.config'/'academy-registry-client'
assert not p.is_symlink() and not p.exists(), 'Choose a fresh client directory'
p.parent.mkdir(mode=0o700,exist_ok=True)
assert not p.parent.is_symlink()
p.mkdir(mode=0o700)
f=p/'config.json'
with f.open('x',encoding='utf-8') as out:
    json.dump({'credHelpers':{'registry.example.net':'pass'}},out)
os.chmod(f,0o600)
print('Only helper routing written; no password in JSON')
PY
docker --config "$HOME/.config/academy-registry-client" login 'registry.example.net' --username 'academy-publisher'
How do I know it worked?

Login Succeeded; config.json contains helper routing without an auth/password entry.

Explore all tutorials ↗