Harbor เป็น container registry ที่ได้รับความนิยมมากในปัจจุบัน เนื่องจากมีความสามารถที่ช่วยให้เก็บ container image ไว้ภายในองค์กรแล้วยังมีความสามารถอื่นๆ เช่น การทำ proxy ไปยัง container registry ภายนอกเช่น docker hub เพื่อลดจำนวน request ไม่ให้ติดปัญหา request limit ของ docker hub การทำ replication ระหว่าง Harbor ด้วยกันกรณี DC/DR use case และ integrate กับ container scanning เช่น Trivy, Clair และ Notary สำหรับการทำ image signed เพื่อป้องกันการแก้ไขเปลี่ยนแปลง image
ในการติดตั้ง Harbor ต้องการ Docker และ Docker Compose ขั้นตอนการ install docker ขึ้นอยู่กับ OS โดยตัวอย่างนี้ติดตั้งบน Linux Rocky
#!/bin/bash
# Docker Installation Script for Rocky Linux
# 1. Update system packages
sudo dnf update -y
# 2. Install required packages
sudo dnf install -y dnf-utils device-mapper-persistent-data lvm2
# 3. Add Docker's official repository
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 4. Install Docker Engine
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# 5. Start and enable Docker service
sudo systemctl start docker
sudo systemctl enable docker
# 6. Add current user to docker group (to run docker without sudo)
sudo usermod -aG docker $USER
# 7. Verify Docker installation
sudo docker --version
sudo docker run hello-world
# 8. Check Docker service status
sudo systemctl status docker
# 9. Optional: Install Docker Compose (if not using plugin version)
# sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# sudo chmod +x /usr/local/bin/docker-compose
echo "Docker installation completed!"
echo "Please log out and log back in for group changes to take effect."
echo "Then you can run 'docker ps' without sudo."
กรณีที่ enable firewall จะต้องทำการ allow service docker ด้วย
# Open Docker ports if firewall is enabled
sudo firewall-cmd --permanent --add-service=docker
sudo firewall-cmd --reload
กรณีนี้ติดตั้งด้วยการใช้ self-signed certificate จำเป็นต้องสร้างไฟล์ daemon.json และใส่ค่า insecure โดยระบุทั้ง host name, host domain และ IP ถ้าไม่ได้สร้าง record บน DSN server
[nutanix@harbor harbor]$ more /etc/docker/daemon.json
{
"insecure-registries": ["harbor.local", "10.55.10.75"]
}
ต้อง restart docker หลังจากสร้างไฟล์ daemon.json เพื่อให้ค่า configuration ถูกนำไปใช้
[nutanix@harbor harbor]$ sudo systemctl restart docker
ทำการ download harbor installation binary และสร้างไฟล์ที่เกี่ยวข้อง
[nutanix@harbor harbor]$ HARBOR_VERSION=$(curl -s https://api.github.com/repos/goharbor/harbor/releases/latest | grep 'tag_name' | cut -d\" -f4)
[nutanix@harbor harbor]$ echo $HARBOR_VERSION
v2.13.1
[nutanix@harbor harbor]$ wget "https://github.com/goharbor/harbor/releases/download/${HARBOR_VERSION}/harbor-offline-installer-${HARBOR_VERSION}.tgz"
[nutanix@harbor harbor]$ tar xvf harbor-offline-installer-${HARBOR_VERSION}.tgz
[nutanix@harbor harbor]$ cd harbor
[nutanix@harbor harbor]$ cp harbor.yml.tmpl harbor.yml
[nutanix@harbor harbor]$ mkdir certs
[nutanix@harbor harbor]$ mkdir data
[nutanix@harbor harbor]$ mkdir generate-cert
ทำการ generate certificate สำหรับ Harbor ตัวอย่างนี้จะตั้ง host name เป็น harbor.local โดยเป็น self-signed certificate
# Generate CA Key
[nutanix@harbor harbor]$ cd generate-cert
[nutanix@harbor generate-cert]$ openssl genrsa -out ca.key 4096
# Generate CA certificate
[nutanix@harbor generate-cert]$ openssl req -x509 -new -nodes -sha512 -days 3650 \
-subj "/C=TH/ST=TH/L=BK/O=IT/OU=IT/CN=harbor.local" \
-key ca.key \
-out ca.crt
#Generate Server key
[nutanix@harbor generate-cert]$ openssl genrsa -out harbor.local.key 4096
# Generate CSR (Certificate Signing Requests)
[nutanix@harbor generate-cert]$ openssl req -sha512 -new \
-subj "/C=TH/ST=TH/L=BK/O=IT/OU=IT/CN=harbor.local" \
-key harbor.local.key \
-out harbor.local.csr
# Create file v3.ext
[nutanix@harbor generate-cert]$ vi v3.ext
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.0=harbor.local
IP.0=10.55.10.75 #harbor IP address
# Generate Server Certificate signed with above CA generated
[nutanix@harbor generate-cert]$ openssl x509 -req -sha512 -days 3650 \
-extfile v3.ext \
-CA ca.crt -CAkey ca.key -CAcreateserial \
-in harbor.local.csr \
-out harbor.local.crt
# Optional - Convert the certificate to PEM format for docker
[nutanix@harbor generate-cert]$ openssl x509 -inform PEM -in harbor.local.crt -out harbor.local.cert
#copy harbor.local.crt and harbor.local.key for harbor server
[nutanix@harbor generate-cert]$ cp harbor.local.crt ../certs
[nutanix@harbor generate-cert]$ cp harbor.local.key ../certs
แก้ไขไฟล์ harbor.yml โดยมีค่าที่จำเป็นต้องแก้ดังนี้
hostname:
certificate:
private_keys:
data_volume:
hostname เป็น domain name ที่ map ไว้ที่ DNS server แต่ถ้าไม่มี DNS server สามารถใช้ IP แทนได้ดังตัวอย่างนี้
Certificate และ private_keys ได้จากขึ้นตอนสร้าง certificate ข้างต้น
data_volume คือข้อมูลระบบและ docker image ที่จัดเก็บใน harbor จำเป็นในการ backup กรณีระบบมีปัญหา และต้องการ recover


run install command เพื่อติดตั้ง harbor ทั้งนี้สามารถติดตั้ง components อื่นๆ ร่วมด้วยโดยใช้ options –with-trivy –with-notary –with-clair –with-chartmuseum
trivy และ clair สำหรับ vulnerability scanner และ notary สำหรับ container signing และ chartmuseum เพื่อให้ harbor สามารถเก็บ helm chart ได้ ตัวอย่างนี้จะติดตั้งเฉพาะ harbor
[nutanix@harbor harbor]$ sudo ./install.sh
หลังจากติดตั้งเสร็จ ทดสอบ login
[nutanix@harbor harbor]$ docker login 10.55.10.75
Username: admin
Password:
WARNING! Your credentials are stored unencrypted in '/home/nutanix/.docker/config.json'.
Configure a credential helper to remove this warning. See
https://docs.docker.com/go/credential-store/
Login Succeeded
กรณีที่ต้องการทำ registry proxy จะต้องไปสร้าง enpoint ที่ต้องการ connect ก่อน โดยเข้าไปที่เมนู Registries และ click +NEW ENDPOINT

กรณีนี้เลือก Docker Hub จากนั้นกรอกข้อมูล Access ID และ Access Secret เพื่อ connect ไปยัง Docker hub โดยต้องไปสร้าง access token ที่ Docker Hub ก่อน สามารถทำทดสอบการเชื่อมต่อโดย click TEST CONNECTION กด OK เพื่อเพิ่ม Endpoint

สร้าง Projects โดยเข้าไปที่เมนู Projects และ click + NEW PROJECT

กรอกข้อมูล Project name เลือก Access Level เลือก Proxy Cache และเลือก endpoint ที่สร้างในขั้นต้น และ click OK เพื่อสร้าง Project

สร้าง Projects อื่นๆ ตัวอย่างนี้สร้าง Project mirror สำหรับติดตั้ง NKP

กรอกข้อมูล Project

Project ที่สร้างขึ้น

