The advent of cloud-native environments brought along the need for Docker image registries. Harbor, a project graduated at Cloud Native Computing Foundation (CNCF), is an open-source Docker image registry that caters to this need. This guide will walk you through the process to execute a successful
Install Harbor
on Ubuntu 22.04 server using Docker.
Introduction
Harbor is a Docker image registry that provides a platform to store and distribute container images securely. With features like policy-based image replication, vulnerability scanning, and role-based access control, Harbor ensures that the images are vulnerability-free and the users pull them from a trusted registry.
Prerequisites
To install Harbor on Ubuntu, you need the following:
- An Ubuntu 22.04 server with a hostname (for this guide, we’ll use ‘harbor-server’).
- A non-root user with root/administrator privileges.
- A domain name or local domain for Harbor.
Step 1: Installing Docker CE (Community Edition)
Harbor can be deployed to Kubernetes via the Helm chart or installed with Docker. We’ll go with the Docker engine for this guide. To install Docker CE on your Ubuntu server, follow these steps:
sudo apt install \
ca-certificates \
curl \
gnupg \
lsb-release
When prompted, type ‘y’ and press ENTER.
Next, download the GPG key for Docker’s repository and add the official Docker repository:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Refresh your package index:
sudo apt update
Install Docker CE and Docker Compose:
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
When prompted, type ‘y’ and press ENTER.
Verify Docker status:
sudo systemctl is-enabled docker
sudo systemctl status docker
If Docker is correctly installed, the service should be running and enabled.
Step 2: Downloading Harbor Installer
To install Harbor, download its installer package. There are two types of Harbor installers: offline and online. For this guide, we’ll use the offline installer.
cd /tmp
curl -s https://api.github.com/repos/goharbor/harbor/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep '\\.tgz$' | wget -i -
tar -xzvf harbor-offline-installer-v2.6.1.tgz
sudo mv harbor /opt/
Step 3: Configuring Harbor Installation
After downloading the Harbor installer, you need to set up the installation. Configuration is done via the ‘harbor.yml’ file included in the Harbor package. Before you start, ensure that your domain name is pointed to the server IP address and you have generated SSL certificates to secure Harbor.
Move to the Harbor installation directory:cd /opt/harbor
Copy the Harbor configuration template:cp harbor.yml.tmpl harbor.yml
sudo nano harbor.yml
Configure the file as shown below:
hostname: registry.test.com
https:
port: 443
certificate: /etc/letsencrypt/live/registry.test.com/fullchain.pem
private_key: /etc/letsencrypt/live/registry.test.com/privkey.pem
harbor_admin_password: Harbor_Docker_Ubuntu
database:
password: db_pass_harbor
Save the file and exit the editor.
Step 4: Installing Harbor via Installer Script and Docker Compose
Now that you’ve set up the base configuration file, start the Harbor installation via the installer script 'install.sh'
in the Harbor installation directory '/opt/harbor'.sudo ./install.sh
The installer script will check the system requirements, prepare the system environment, generate the necessary configurations, and start the Harbor installation.
Step 5: Verifying Harbor Installation
After installing Harbor, verify it by checking the container services on your system and accessing the Harbor image registry via a web browser.lsdocker compose ps
Open your web browser and visit your Harbor installation domain (i.e: https://registry.test.com/
). Log in with the default user admin and the password you configured earlier.
Step 6: Creating Harbor User
Once the Harbor image registry is up and running, you need to set up and create a new user via the Harbor administration dashboard.
Step 7: Adding User to Harbor Project
In Harbor, users work within a space called a project. By default, Harbor provides a project named 'library'
.
Step 8: Logging in to Harbor via Docker Client
Once you’ve set up a user, log in to the Harbor image registry via the Docker CLI.docker login https://registry.test.com/
Step 9: Pushing Images to Harbor Registry
After authentication, you can now push images to the Harbor image registry.
docker pull nginx:alpine
docker images
docker tag nginx:alpine registry.test.com/library/nginx:alpine
docker push registry.test.com/library/nginx:alpine
Conclusion
And that’s it! You have successfully managed to install Harbor on an Ubuntu 22.04 server via Docker. Harbor now runs securely through an HTTPS connection, and you’ve learned the basic administration of managing users and projects in Harbor, as well as uploading an image.
As a next step, you can add more users and set up new projects for your development team.
For Linux SSD VPS solutions that can easily handle Docker and Harbor, consider Shape.host. They offer excellent customer service, superior uptime, and affordable pricing.