Cyberithub

How to Install Harbor on Ubuntu 20.04 LTS [Step by Step]

Advertisements

In this article, I will take you through the steps to install harbor on Ubuntu 20.04 LTS. Harbor is an open source registry that secures artifacts with policies and role-based access control, ensures images are scanned and free from vulnerabilities, and signs images as trusted. It is slowly gaining popularity as a successor of other available registry and artifactory like JFrog and Nexus. It is due to its delivery of compliance, performance, and interoperability to help you consistently and securely manage artifacts across cloud native compute platforms like Kubernetes and Docker. You can check more about this on official website.

Harbor Components

Harbor primarily consists of eight different components:-

  • Postgresql : It is the database used by the Harbor.
  • Redis: It is an in-memory database used for storing the login information.
  • Beego: It is an open source web app framework over which Harbor web service is being built and developed.
  • Chartmuseum: It is used to manage Helm Charts.
  • Docker/distribution: It is used for pushing and pulling of docker images.
  • Docker/notary: It is used for signing and verifying docker images.
  • Helm: It uses a packaging format called charts. Since version 1.6.0 Harbor is now a composite cloud-native registry which supports both container image management and Helm charts management.
  • Swagger-ui: It is used to call and test RESTful API.

How to Install Harbor on Ubuntu 20.04 LTS [Step by Step]

How to Install Harbor on Ubuntu 20.04 LTS

Also Read: How to Install Vagrant on Ubuntu 20.04 LTS [Step by Step]

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS Server.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or apt-get utility available in your System

d) You should have curl, gpg and tar utility installed in your System.

 

Step 2: Update Your Server

It is essential to run System update using apt update or apt-get update command to let the System know about any updates or any new packages available in the repo.

root@localhost:~# apt update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:3 http://ppa.launchpad.net/hluk/copyq/ubuntu focal InRelease
Hit:4 https://download.docker.com/linux/ubuntu focal InRelease
Get:5 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Hit:6 https://artifacts.elastic.co/packages/oss-7.x/apt stable InRelease
Hit:7 https://dl.google.com/linux/chrome/deb stable InRelease
Get:8 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Ign:9 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 InRelease
Hit:10 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 Release
Get:11 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [277 kB]
Get:13 http://in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [363 kB]
Get:14 http://in.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [940 B]
Get:15 http://in.archive.ubuntu.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [7,988 B]
Get:16 http://in.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [11.3 kB]

 

Step 3: Install Docker

Since harbor will be deployed as docker containers so it requires you to install the docker package first.

a) Download GPG Key

You can visit the docker official page and add the Docker official GPG Key using below curl command.

root@localhost:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

b) Setup Repository

As the docker is not available through default Ubuntu repo and is only available through docker repository, you need to run below command to setup the stable repository.

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

c) Update Your Server

Then run apt update or apt-get update command again to let the System know about all the packages available in the newly added repo. Without this, system won't able to find the docker package.

root@localhost:~# apt update
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu focal InRelease
Ign:3 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 InRelease
Get:4 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:5 http://ppa.launchpad.net/hluk/copyq/ubuntu focal InRelease
Get:6 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:8 https://artifacts.elastic.co/packages/oss-7.x/apt stable InRelease [10.4 kB]
Hit:9 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 Release
Hit:10 https://dl.google.com/linux/chrome/deb stable InRelease

d) Install Package

Finally install docker and other required packages from repo by using apt-get install docker-ce docker-ce-cli containerd.io command as shown below.

root@localhost:~# apt-get install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
i965-va-driver intel-media-va-driver kwayland-data kwayland-integration libaacs0 libaom0 libass9 libavcodec58 libavdevice58 libavfilter7 libavformat58
libavresample4 libavutil56 libbdplus0 libbluray2 libbs2b0 libchromaprint1 libcodec2-0.9 libdbusmenu-qt5-2 libdc1394-22 libfam0 libfftw3-double3 libflite1
libgme0 libgsm1 libigdgmm11 libkf5config-bin libkf5config-data libkf5configcore5 libkf5coreaddons-data libkf5coreaddons5 libkf5guiaddons5 libkf5idletime5
libkf5notifications-data libkf5notifications5 libkf5waylandclient5 libkf5windowsystem-data libkf5windowsystem5 liblilv-0-0 libllvm11 libmysofa1 libnorm1
libopenal-data libopenal1 libopenmpt0 libpgm-5.2-0 libpostproc55 libqt5texttospeech5 librubberband2 libsdl2-2.0-0 libserd-0-0 libshine3 libsnappy1v5
libsndio7.0 libsord-0-0 libsratom-0-0 libssh-gcrypt-4 libswresample3 libswscale5 libtie-ixhash-perl libva-drm2 libva-x11-2 libva2 libvdpau1 libvidstab1.1
libx264-155 libx265-179 libxml-xpathengine-perl libxvidcore4 libzmq5 libzvbi-common libzvbi0 linux-headers-5.11.0-40-generic
linux-hwe-5.11-headers-5.11.0-40 linux-image-5.11.0-40-generic linux-modules-5.11.0-40-generic linux-modules-extra-5.11.0-40-generic mesa-va-drivers
mesa-vdpau-drivers va-driver-all vdpau-driver-all
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
docker-scan-plugin pigz
Suggested packages:
aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
containerd.io docker-ce docker-ce-cli docker-scan-plugin pigz
0 upgraded, 5 newly installed, 0 to remove and 43 not upgraded.
Need to get 3,575 kB/89.2 MB of archives.
After this operation, 388 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

 

Step 4: Install Docker Compose

Next step is to install Docker Compose as it is required to manage the lifecycle of Harbor.

a) Download Binary

You don't really need to install Compose on your System but just have to download the executable package under /usr/local/bin directory using below command.

root@localhost:~# curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 664 100 664 0 0 3905 0 --:--:-- --:--:-- --:--:-- 3905
100 12.1M 100 12.1M 0 0 9473k 0 0:00:01 0:00:01 --:--:-- 20.1M

b) Provide Execute Permission

Then provide execute permission by using chmod +x /usr/local/bin/docker-compose command.

root@localhost:~# chmod +x /usr/local/bin/docker-compose

 

Step 5: Download Harbor

You can go to Harbor Github Page and download the latest offline package using any of the file transfer utilities like wget or curl. Here I am using below wget command to download the latest Harbor package. At the time of writing, 2.4.1 is the latest available package.

root@localhost:~# wget https://github.com/goharbor/harbor/releases/download/v2.4.1/harbor-offline-installer-v2.4.1.tgz
--2021-12-18 18:00:40-- https://github.com/goharbor/harbor/releases/download/v2.4.1/harbor-offline-installer-v2.4.1.tgz
Resolving github.com (github.com)... 13.234.210.38
Connecting to github.com (github.com)|13.234.210.38|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/50613991/7e5db83b-31c3-451b-bf71-6a0aa1036305?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20211218%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211218T123041Z&X-Amz-Expires=300&X-Amz-Signature=4e53fa51e1326359de94278932b69b9179eaf1beec9dadfb60a65796bd5dd6c8&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=50613991&response-content-disposition=attachment%3B%20filename%3Dharbor-offline-installer-v2.4.1.tgz&response-content-type=application%2Foctet-stream [following]
--2021-12-18 18:00:41-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/50613991/7e5db83b-31c3-451b-bf71-6a0aa1036305?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20211218%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211218T123041Z&X-Amz-Expires=300&X-Amz-Signature=4e53fa51e1326359de94278932b69b9179eaf1beec9dadfb60a65796bd5dd6c8&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=50613991&response-content-disposition=attachment%3B%20filename%3Dharbor-offline-installer-v2.4.1.tgz&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.108.133, 185.199.111.133, 185.199.110.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 612698835 (584M) [application/octet-stream]
Saving to: ‘harbor-offline-installer-v2.4.1.tgz’

harbor-offline-installer-v2.4.1.tgz 100%[============================================================================>] 584.31M 12.4MB/s in 45s

2021-12-18 18:01:27 (13.0 MB/s) - ‘harbor-offline-installer-v2.4.1.tgz’ saved [612698835/612698835]

 

Step 6: Extract Harbor Package

If you have tar utility available then you can extract the package by using tar -xvzf harbor-offline-installer-v2.4.1.tgz command. This will extract all the contents under harbor directory in the current location.

root@localhost:~# tar -xvzf harbor-offline-installer-v2.4.1.tgz
harbor/harbor.v2.4.1.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl

 

Step 7: Configure Harbor

After extracting the package, you can go to harbor directory by using cd harbor command then list out the contents using ls command.

root@localhost:~# cd harbor
root@localhost:~/harbor# ls
common.sh harbor.v2.4.1.tar.gz harbor.yml.tmpl install.sh LICENSE prepare

Here we need to take the configuration from harbor.yml.tmpl and edit it according to our requirements before going for the installation. So we will first copy the contents to harbor.yml file using cp harbor.yml.tmpl harbor.yaml command. This file will be required by the Harbor installation script to know the information like hostname, Port number, SSL Cert path, admin password etc. Then we will open the file using nano harbor.yml command and provide all the required details.

For the moment, I will provide the minimum details required to install Harbor but you can always edit and provide all the information as per your requirements. I am leaving all the settings as default except changing the hostname to harbor.example.com and commenting out the https certificate path as I am not using any SSL certificate now. It is fine for a demo environment but if you are installing Harbor in a Production environment then it is highly recommended to generate a SSL certificate signed by the Certificate Authority and use it for secure HTTPS communication.

NOTE:

Please note that here I am using locally setup FQDN harbor.example.com to access admin UI. This URL will be pointing to my local Server IP address for which I have given an entry in /etc/hosts file. You can also perform such setup to access Harbor UI through FQDN.
root@localhost:~/harbor# cp harbor.yml.tmpl harbor.yml
root@localhost:~/harbor# nano harbor.yml

# Configuration file of Harbor

# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: harbor.example.com

# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 80

# https related config
#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

# # Uncomment following will enable tls communication between all harbor components
# internal_tls:
# # set enabled to true means internal tls is enabled
# enabled: true
# # put your cert and key files on dir
# dir: /etc/harbor/tls/internal

# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
# external_url: https://reg.mydomain.com:8433

# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: Harbor12345

 

Step 8: Install Harbor

After finishing up with the configuration, you can now run the installation script by using ./install.sh as shown below. This will perform the step by step check and verify if all the prerequisites are installed and then only it will start loading all the docker images. Finally, if all goes well then you will see Harbor getting installed and started successfully as shown below.

root@localhost:~/harbor# ./install.sh

[Step 0]: checking if docker is installed ...

Note: docker version: 20.10.12

[Step 1]: checking docker-compose is installed ...

Note: docker-compose version: 1.29.2

[Step 2]: loading Harbor images ...
1e3f0dc884e2: Loading layer [==================================================>] 39.45MB/39.45MB
3fd9ccd5eeaa: Loading layer [==================================================>] 5.275MB/5.275MB
c600bceee2f7: Loading layer [==================================================>] 4.096kB/4.096kB
724cd8711815: Loading layer [==================================================>] 3.072kB/3.072kB
d7c82a981c89: Loading layer [==================================================>] 17.32MB/17.32MB
a814341c2c44: Loading layer [==================================================>] 18.12MB/18.12MB
Loaded image: goharbor/registry-photon:v2.4.1

.................................................

[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-portal ... done
Creating registryctl ... done
Creating harbor-db ... done
Creating registry ... done
Creating redis ... done
Creating harbor-core ... done
Creating harbor-jobservice ... done
Creating nginx ... done
✔ ----Harbor has been installed and started successfully.----

 

Step 9: Open Harbor UI

After successful installation, you can go to your favorite website and open your local Server URL http://harbor.example.com as shown below. Once opened, it will ask you to put Username and Password to login. Your default username will be admin and password will be the same as you have set in the earlier step i.e Harbor12345.

How to Install Harbor on Ubuntu 20.04 LTS [Step by Step] 2

Upon successful authentication, you will be redirected to Harbor Projects page as shown below. This pretty much completes the Harbor installation. Now you can proceed with its usage.

How to Install Harbor on Ubuntu 20.04 LTS [Step by Step] 3

Leave a Comment