Harbor is an open-source cloud-native registry that provides a secure and scalable platform for storing, signing, and distributing container images. Developed by VMware, Harbor offers enterprises and developers a comprehensive solution for managing container artifacts, ensuring compliance, and promoting collaboration across the software development lifecycle.

In this guide, we will show you how to install the Harbor registry on Ubuntu 22.04.

Step 1 – Install Docker CE

By default, the latest Docker version is unavailable in the Ubuntu default repo, so you will need to install it from their official repo.

First, install all the necessary dependencies:

apt update -y
apt install ca-certificates curl gnupg lsb-release -y

Next, create a directory to store the Docker GPG key.

mkdir -p /etc/apt/keyrings

Next, download the GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Next, add the Docker repository to the APT source file.

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu   $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

Next, update the repository cache:

apt update -y

Finally, install Docker CE and other required tools using the following command:

apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y

You can verify the status of the Docker service using the following command:

systemctl status docker

Output:

● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2024-02-09 07:48:16 UTC; 1h 4min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 27927 (dockerd)
      Tasks: 84
     Memory: 263.4M
        CPU: 1min 40.313s
     CGroup: /system.slice/docker.service
             ├─27927 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
             ├─34566 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3478 -container-ip 172.21.0.4 -container-port 3478
             ├─34572 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 3478 -container-ip 172.21.0.4 -container-port 3478
             ├─34586 /usr/bin/docker-proxy -proto udp -host-ip 0.0.0.0 -host-port 3478 -container-ip 172.21.0.4 -container-port 3478
             ├─34591 /usr/bin/docker-proxy -proto udp -host-ip :: -host-port 3478 -container-ip 172.21.0.4 -container-port 3478
             ├─35803 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 443 -container-ip 172.21.0.10 -container-port 443
             ├─35809 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 443 -container-ip 172.21.0.10 -container-port 443
             ├─35825 /usr/bin/docker-proxy -proto udp -host-ip 0.0.0.0 -host-port 443 -container-ip 172.21.0.10 -container-port 443
             └─35833 /usr/bin/docker-proxy -proto udp -host-ip :: -host-port 443 -container-ip 172.21.0.10 -container-port 443

Step 2 – Install Harbor

First, download the latest version of Harbor from the Git repository.

curl -s https://api.github.com/repos/goharbor/harbor/releases/latest | grep browser_download_url | cut -d '"' -f 4 | grep '\.tgz$' | wget -i -

Once the download is completed, extract the downloaded file using the tar command:

tar -xzvf harbor-online-installer-v2.10.0.tgz

Next, move the extracted directory to the /opt directory.

mv harbor /opt/

Next, navigate to the Harbor directory and copy the Harbor configuration file.

cd /opt/harbor
cp harbor.yml.tmpl harbor.yml

Next, edit the Harbor configuration file.

nano harbor.yml

Change the following lines:

hostname: reg.example.com

harbor_admin_password: Harbor12345

Remove the following lines:

https:
  # https port for harbor, default is 443
  port: 443
  # The path of cert and key files for nginx
  certificate: /your/certificate/path
  private_key: /your/private/key/path

Save and close the file when you are done.

Next, run the following command to install the Harbor:

./install.sh

You will see the following output:

[Step 4]: starting Harbor ...
[+] Running 9/10
 ⠧ Network harbor_harbor        Created                                                                                                                            1.8s 
 ✔ Container harbor-log         Started                                                                                                                            0.4s 
 ✔ Container harbor-db          Started                                                                                                                            0.9s 
 ✔ Container harbor-portal      Started                                                                                                                            0.8s 
 ✔ Container redis              Started                                                                                                                            1.0s 
 ✔ Container registry           Started                                                                                                                            0.7s 
 ✔ Container registryctl        Started                                                                                                                            1.0s 
 ✔ Container harbor-core        Started                                                                                                                            1.2s 
 ✔ Container nginx              Started                                                                                                                            1.6s 
 ✔ Container harbor-jobservice  Started                                                                                                                            1.6s 
✔ ----Harbor has been installed and started successfully.----

You can verify all running containers using the following command:

docker compose ps

Output:

NAME                IMAGE                                 COMMAND                  SERVICE       CREATED          STATUS                             PORTS
harbor-core         goharbor/harbor-core:v2.10.0          "/harbor/entrypoint.…"   core          13 seconds ago   Up 12 seconds (health: starting)   
harbor-db           goharbor/harbor-db:v2.10.0            "/docker-entrypoint.…"   postgresql    13 seconds ago   Up 12 seconds (health: starting)   
harbor-jobservice   goharbor/harbor-jobservice:v2.10.0    "/harbor/entrypoint.…"   jobservice    13 seconds ago   Up 11 seconds (health: starting)   
harbor-log          goharbor/harbor-log:v2.10.0           "/bin/sh -c /usr/loc…"   log           13 seconds ago   Up 13 seconds (health: starting)   127.0.0.1:1514->10514/tcp
harbor-portal       goharbor/harbor-portal:v2.10.0        "nginx -g 'daemon of…"   portal        13 seconds ago   Up 12 seconds (health: starting)   
nginx               goharbor/nginx-photon:v2.10.0         "nginx -g 'daemon of…"   proxy         13 seconds ago   Up 11 seconds (health: starting)   0.0.0.0:80->8080/tcp, :::80->8080/tcp
redis               goharbor/redis-photon:v2.10.0         "redis-server /etc/r…"   redis         13 seconds ago   Up 12 seconds (health: starting)   
registry            goharbor/registry-photon:v2.10.0      "/home/harbor/entryp…"   registry      13 seconds ago   Up 12 seconds (health: starting)   
registryctl         goharbor/harbor-registryctl:v2.10.0   "/home/harbor/start.…"   registryctl   13 seconds ago   Up 12 seconds (health: starting) 

Step 3 – Access Harbor Web UI

At this point, the Harbor registry is installed in the Docker container. You can now access it using the URL http://reg.example.com. You will see the Harbor login page:

Provide the default username admin and the password that you have configured via the configuration file harbor.yml, then click on the LOG IN button. You will see the Harbor dashboard on the following page.

Conclusion

By deploying Harbor, you gain control over your container image lifecycle, ensuring compliance with security policies, regulatory requirements, and best practices for containerized application development and deployment. Harbor’s intuitive user interface, RESTful API, and integration capabilities enable seamless integration with your existing infrastructure, CI/CD pipelines, and identity providers, fostering collaboration and accelerating software delivery cycles. You can now try to host your own image hosting registry using Harbor on dedicated server hosting from Atlantic.Net!