Installing Harbor Private Registry on Ubuntu 22.04: Securing Images with HTTPS and Trivy

Ubuntu tutorial - IT technology blog
Ubuntu tutorial - IT technology blog

Pushing container images with proprietary source code to Docker Hub is like leaving valuables in a street-side parking lot. Even when set to private, you still depend on external infrastructure and burn bandwidth downloading images repeatedly. Ops teams need a private registry on the internal network, complete with a locked door (HTTPS) and an automated security scanner (Trivy). Harbor solves that exact problem.

I deployed this setup on an Ubuntu 22.04 staging server for a team of about 15 developers, storing over 120 images totaling nearly 70GB before rolling it out to production.

Quick start: Install Harbor Private Registry in 5 minutes

Prepare an Ubuntu 22.04 server with at least 2 vCPUs, 4GB of RAM, and 40GB of disk space. The server must already have Docker Engine and the Docker Compose plugin (v2) installed.

Step 1: Download the Harbor installer

Download the offline installer (for example, v2.11.0, around 650MB) from Harbor’s official release page and extract it:

wget https://github.com/goharbor/harbor/releases/download/v2.11.0/harbor-offline-installer-v2.11.0.tgz
tar xzvf harbor-offline-installer-v2.11.0.tgz
cd harbor

Step 2: Create the basic configuration file

Copy the provided template file to harbor.yml to start editing:

cp harbor.yml.tmpl harbor.yml
nano harbor.yml

Change hostname to your IP address or internal domain (for example, registry.noibo.local) and set a strong harbor_admin_password. If you only want to run a quick test over HTTP, temporarily comment out the https: block. We will enable HTTPS in the next section.

Step 3: Run the installation script with Trivy

Run the installer script so Harbor automatically spins up its service containers along with the Trivy scanner:

sudo ./install.sh --with-trivy

Wait about 2–3 minutes for Docker to load the images and start the 10 component containers. Once finished, open your browser, navigate to the server address, and log in with the admin user.

Deep dive: How Harbor works and configuring HTTPS

Think of Harbor as an automated warehouse. Core and Registry act as the security guards checking badges at the gate. PostgreSQL and Redis serve as the warehouse clerks logging who pushed which build and when. Meanwhile, Trivy is the X-ray machine inspecting every single package.

Why enable HTTPS for the Registry?

By default, Docker refuses to connect to registries running over plain HTTP. Unencrypted connections make it easy for passwords to leak or images to be tampered with in transit. That is why you should configure HTTPS even on a local LAN.

Configuring SSL certificates in harbor.yml

Don’t have a public domain? You can easily generate a self-signed SSL certificate using OpenSSL for your internal network:

sudo mkdir -p /etc/harbor/ssl
cd /etc/harbor/ssl

# Create Root CA
openssl genrsa -out ca.key 4096
openssl req -x509 -new -nodes -sha512 -days 3650 \
  -subj "/C=VN/ST=Hanoi/L=Hanoi/O=Internal/CN=Harbor-CA" \
  -key ca.key -out ca.crt

# Create Private Key and CSR for the server
openssl genrsa -out registry.key 4096
openssl req -sha512 -new \
  -subj "/C=VN/ST=Hanoi/L=Hanoi/O=Internal/CN=registry.noibo.local" \
  -key registry.key -out registry.csr

# Sign the certificate for the domain
cat <<EOF > v3.ext
subjectAltName = DNS:registry.noibo.local,IP:192.168.1.50
extendedKeyUsage = serverAuth
EOF

openssl x509 -req -sha512 -days 3650 \
  -extfile v3.ext \
  -CA ca.crt -CAkey ca.key -CAcreateserial \
  -in registry.csr -out registry.crt

Reopen harbor.yml, uncomment the https: section, and point it to the certificate paths you just created:

https:
  port: 443
  certificate: /etc/harbor/ssl/registry.crt
  private_key: /etc/harbor/ssl/registry.key

Go back to the extracted Harbor directory (for example, ~/harbor), apply the new configuration, and restart the services:

cd ~/harbor
sudo ./prepare --with-trivy
sudo docker compose down
sudo docker compose up -d

On any developer machines or Ubuntu servers that need to push/pull images, copy ca.crt into Docker’s trusted certificate directory to avoid SSL verification errors:

sudo mkdir -p /etc/docker/certs.d/registry.noibo.local
sudo cp ca.crt /etc/docker/certs.d/registry.noibo.local/ca.crt
sudo systemctl restart docker

Try logging in and pushing a small image (around 4MB) to your private registry:

docker login registry.noibo.local
docker pull nginx:alpine
docker tag nginx:alpine registry.noibo.local/library/nginx:alpine
docker push registry.noibo.local/library/nginx:alpine

Integrating the Trivy vulnerability scanner

Thanks to the --with-trivy flag, Harbor comes with Trivy built in to scan both OS packages (Debian, Alpine, Ubuntu) and application libraries (Node.js, Python, Go). Open any Project in the web UI, go to the Configuration tab, and check Automatically scan images on push. From then on, every newly pushed image is scanned automatically and labeled with severity levels ranging from Low to Critical.

Advanced: Project permissions, blocking vulnerable images, and garbage collection

When 3–4 teams push images to the same Harbor instance, setting clear boundaries and automatically blocking risks saves you a lot of headaches.

Managing Projects, RBAC, and Robot Accounts

Never share the admin account across the entire company. Create a dedicated Private Project for each product group, such as backend-api or frontend-web. Then assign clear RBAC roles: Developers get push/pull access, while QA or Guests only get pull access.

For CI/CD pipelines (GitLab CI, Jenkins, GitHub Actions), never use personal passwords. Go to Robot Accounts inside the Project to issue dedicated tokens, restrict permissions, and set an expiration date (such as 90 days).

Enabling Vulnerability Prevention (Blocking vulnerable image pulls)

This is Harbor’s most valuable feature. Under a Project’s Configuration tab, enable Prevent vulnerable images from running and set the threshold to High. Any image containing High or Critical CVEs (such as an RCE flaw in the openssl library) will be blocked from being pulled right at the gate.

Configuring Garbage Collection (Reclaiming disk space)

Deleting an image tag in the web UI does not free up disk space immediately. Harbor only removes the reference (manifest), while the underlying data layers remain on disk. Go to Administration > Garbage Collection to schedule regular cleanup jobs—for example, every Sunday at 2:00 AM—to reclaim tens of gigabytes of unused space.

Practical tips for operating Harbor on Ubuntu

After running Harbor for our internal infrastructure for 6 months, here are 4 lessons I learned to avoid midnight incident responses:

  • Mount a dedicated disk for the data directory: By default, Harbor stores all images and databases in /data. You should mount a separate disk or volume (at least 100GB if your team builds frequently) to /data to prevent filling up the root / partition and freezing the server.
  • Back up before every upgrade: Always back up the entire /data directory along with harbor.yml before running the upgrade script for a new Harbor version.
  • Tighten UFW firewall rules: Only open port 443 (HTTPS) for your internal IP range and port 22 (SSH) for administrators. PostgreSQL and Redis ports only run inside Docker’s internal network by default and do not need to be exposed externally.
  • Sync the Trivy database in air-gapped networks: Trivy needs internet access to download new CVE data from GitHub Container Registry. If your server sits in an isolated (air-gapped) environment, you will need to periodically copy the trivy.db file over manually.
Share: