Harbor Container Registry on Docker with

๐Ÿ’ก Harbor Container Registry on Docker with โ€” Executive Summary

Technical architectural analysis, practical configuration manifests, and deployment instructions for Harbor Container Registry on Docker with.

Closed network

Ready
ubuntu 20.04

> ๐Ÿ’ก
docker
โ€“ containerd.io/now 1.6.6-1 amd64 \[installed,local\]
โ€“ docker-ce-cli/now 5:19.03.15\~3-0\~ubuntu-focal amd64 \[installed,local\]
โ€“ docker-ce/now 5:19.03.15\~3-0\~ubuntu-focal amd64 \[installed,local\]
โ€“ docker-compose-plugin/now 2.6.0\~ubuntu-focal amd64 \[installed,local\]
โ€“ libseccomp2/now 2.5.1-1ubuntu1\~20.04.2 amd64 \[installed,local\]

docker-compose
โ€“ docker-compose version 1.21.2, build a133471

nfs-common
โ€“ nfs-common/now 1:1.3.4-2.5ubuntu3.4 amd64 \[installed,local\]

pool

> ๐Ÿ’ก
[https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/](https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/)

https://download.docker.com/linux/\{\{os\}\}/dist/\{\{os-ver\}\}/pool/stable/\{\{architecture\}\}/

โ€” Download the items below

โ€“ containerd.io\_1.6.6-1\_amd64.deb
โ€“ docker-ce-cli\_19.03.15\~3-0\~ubuntu-focal\_amd64.deb
โ€“ docker-ce\_19.03.15\~3-0\~ubuntu-focal\_amd64.deb
โ€“ docker-compose-plugin\_2.6.0\~ubuntu-focal\_amd64.deb

[http://archive.ubuntu.com/ubuntu/pool/main/libs/libseccomp/libseccomp2\_2.5.1-1ubuntu1\~20.04.2\_amd64.deb ](http://archive.ubuntu.com/ubuntu/pool/main/libs/libseccomp/libseccomp2_2.5.1-1ubuntu1~20.04.2_amd64.deb)

โ€” Download containerd dependencies

[http://archive.ubuntu.com/ubuntu/pool/universe/d/docker-compose/](http://archive.ubuntu.com/ubuntu/pool/universe/d/docker-compose/)

โ€” Download docker-compose

Installation
bash
# docker.io package ์„ค์น˜
dpkg -i *.deb

# nfs-common package ์„ค์น˜
dpkg -i *.deb

# docker-compose ์„ค์น˜
cp ./docker-compose /usr/bin/

# ๋ฐ์ดํ„ฐ๊ฒฝ๋กœ ์ง€์ •
mkdir /${TARGET_PATH} # /data
# NFS ๋งˆ์šดํŠธ
mount -t nfs ${NFS_SERVER_IP}:/${TARGET_NFS_VOLUME} /${TARGET_PATH}
mount -l | grep data

# ๊ฐ€์ƒ๋จธ์‹  ์žฌ๊ธฐ๋™ ํ•ด๋„ NFS ์ž๋™ ๋งˆ์šดํŠธ
sudo vi /etc/fstab

--- # ์•„๋ž˜ ๋‚ด์šฉ ์ถ”๊ฐ€

${NFS_SERVER_IP}:/${TARGET_NFS_VOLUME}      /${TARGET_PATH}     nfs     defaults        0

---
# harbor ์••์ถ•ํ•ด์ œ
tar xzvf harbor-offline-installer-v2.1.0.tgz

# harbor.yml ์ž‘์„ฑ
cp harbor.yml.tmpl harbor.yml
vi harbor.yml
<--- # ์•„๋ž˜ ๋‚ด์šฉ ๋ณ€๊ฒฝ
hostname: $harbor_domain
#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

harbor_admin_password: $password

# Harbor DB configuration
database:
  # The password for the root user of Harbor DB. Change this before any production use.
  password: $password

# The default data volume
data_volume: /data
...

externalHost ๋ณ€๊ฒฝ( ํ”„๋ก์‹œ ์‚ฌ์šฉ์‹œ )

--->

# harbor ์„ค์น˜
chmod +x install.sh
./install.sh

# insecure ์ง€์ •
vi /etc/docker/daemon.json
<---
{
"insecure-registries" : ["$domain"]
}
--->

# docker ์žฌ์‹œ์ž‘
systemctl restart docker
docker info | grep insecure

# host ๋“ฑ๋ก -- haproxy ๋“ฑ๋ก ํ•„์š”
vi /etc/hosts
{ haproxy host } $harbor_domain

# login
docker login $harbor_domain -u admin -p $password

bash
# ์ •์ƒ์ ์ธ ๊ฒฝ์šฐ
systemctl status docker
>>>
โ— docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-01-11 11:16:41 UTC; 1min 3s ago
TriggeredBy: โ— docker.socket
       Docs: https://docs.docker.com
   Main PID: 19273 (dockerd)
      Tasks: 44
     Memory: 53.8M
     CGroup: /system.slice/docker.service
             โ”œโ”€19273 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
             โ”œโ”€19428 /usr/bin/docker-proxy -proto tcp -host-ip 127.0.0.1 -host-port 1514 -container-ip 172.18.0.2 -container-port 10514
             โ””โ”€19642 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 80 -container-ip 172.18.0.10 -container-port 8080
<<<


https settings

Create certification authority certificate
bash
# CA ์ธ์ฆ์„œ ๊ฐœ์ธํ‚ค ์ƒ์„ฑ
openssl genrsa -out ca.key 4096
# CA ์ธ์ฆ์„œ ์ƒ์„ฑ
# -subj์กฐ์ง์„ ๋ฐ˜์˜ ํ•˜๋„๋ก ์˜ต์…˜์˜ ๊ฐ’์„ ์กฐ์ • ํ•˜์‹ญ์‹œ์˜ค. FQDN์„ ์‚ฌ์šฉํ•˜์—ฌ ํ•˜๋ฒ„ ํ˜ธ์ŠคํŠธ๋ฅผ ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒฝ์šฐ ์ผ๋ฐ˜ ์ด๋ฆ„( CN) ํŠน์„ฑ์œผ๋กœ ์ง€์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
openssl req -x509 -new -nodes -sha512 -days 3650 \
 -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=$domain" \
 -key ca.key \
 -out ca.crt
Generate server certificate
bash
# ๊ฐœ์ธ ํ‚ค ์ƒ์„ฑ
openssl genrsa -out yourdomain.com.key 4096

# ์ธ์ฆ์„œ ์„œ๋ช… ์š”์ฒญ(CSR) ์ƒ์„ฑ
# -subj์กฐ์ง์„ ๋ฐ˜์˜ ํ•˜๋„๋ก ์˜ต์…˜์˜ ๊ฐ’์„ ์กฐ์ • ํ•˜์‹ญ์‹œ์˜ค. FQDN์„ ์‚ฌ์šฉํ•˜์—ฌ Harbor ํ˜ธ์ŠคํŠธ๋ฅผ ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒฝ์šฐ FQDN์„ ์ผ๋ฐ˜ ์ด๋ฆ„( CN) ์†์„ฑ์œผ๋กœ ์ง€์ •ํ•˜๊ณ  ํ‚ค ๋ฐ CSR ํŒŒ์ผ ์ด๋ฆ„์— ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
openssl req -sha512 -new \
    -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=$domain" \
    -key yourdomain.com.key \
    -out yourdomain.com.csr

# x509 v3 ํ™•์žฅ ํŒŒ์ผ์„ ์ƒ์„ฑ
# FQDN ๋˜๋Š” IP ์ฃผ์†Œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Harbor ํ˜ธ์ŠคํŠธ์— ์—ฐ๊ฒฐํ•˜๋Š”์ง€ ์—ฌ๋ถ€์— ๊ด€๊ณ„์—†์ด SAN(์ฃผ์ฒด ๋Œ€์ฒด ์ด๋ฆ„) ๋ฐ x509 v3์„ ์ค€์ˆ˜ํ•˜๋Š” Harbor ํ˜ธ์ŠคํŠธ์— ๋Œ€ํ•œ ์ธ์ฆ์„œ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋„๋ก ์ด ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ํ™•์žฅ ์š”๊ตฌ ์‚ฌํ•ญ. DNS๋„๋ฉ”์ธ์„ ๋ฐ˜์˜ ํ•˜๋„๋ก ํ•ญ๋ชฉ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค .
cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

[alt_names]
DNS.1=yourdomain.com
DNS.2=yourdomain
DNS.3=hostname
EOF

# ํŒŒ์ผ์„ ์‚ฌ์šฉ v3.extํ•˜์—ฌ Harbor ํ˜ธ์ŠคํŠธ์— ๋Œ€ํ•œ ์ธ์ฆ์„œ๋ฅผ ์ƒ์„ฑํ•˜์‹ญ์‹œ์˜ค.
# yourdomain.comCRS ๋ฐ CRT ํŒŒ์ผ ์ด๋ฆ„์„ Harbor ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค .
openssl x509 -req -sha512 -days 3650 \
    -extfile v3.ext \
    -CA ca.crt -CAkey ca.key -CAcreateserial \
    -in yourdomain.com.csr \
    -out yourdomain.com.crt
Provide certificates to Harbor and Docker
bash
# ์„œ๋ฒ„ ์ธ์ฆ์„œ์™€ ํ‚ค๋ฅผ Harbor ํ˜ธ์ŠคํŠธ์˜ ์ธ์ฆ์„œ ํด๋”์— ๋ณต์‚ฌ
cp yourdomain.com.crt /data/cert/
cp yourdomain.com.key /data/cert/

# Docker์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋กœ ๋ณ€ํ™˜
# Docker ๋ฐ๋ชฌ์€ .crtํŒŒ์ผ์„ CA ์ธ์ฆ์„œ๋กœ, .certํŒŒ์ผ์„ ํด๋ผ์ด์–ธํŠธ ์ธ์ฆ์„œ๋กœ ํ•ด์„ํ•ฉ๋‹ˆ๋‹ค.
openssl x509 -inform PEM -in yourdomain.com.crt -out yourdomain.com.cert

# ์„œ๋ฒ„ ์ธ์ฆ์„œ, ํ‚ค ๋ฐ CA ํŒŒ์ผ์„ Harbor ํ˜ธ์ŠคํŠธ์˜ Docker ์ธ์ฆ์„œ ํด๋”์— ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๋จผ์ € ์ ์ ˆํ•œ ํด๋”๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
cp yourdomain.com.cert /etc/docker/certs.d/yourdomain.com/
cp yourdomain.com.key /etc/docker/certs.d/yourdomain.com/
cp ca.crt /etc/docker/certs.d/yourdomain.com/
# nginx๊ธฐ๋ณธ ํฌํŠธ 443์„ ๋‹ค๋ฅธ ํฌํŠธ์— ๋งคํ•‘ํ•œ ๊ฒฝ์šฐ ํด๋” /etc/docker/certs.d/yourdomain.com:port๋˜๋Š” /etc/docker/certs.d/harbor_IP:port.

# Docker ์—”์ง„์„ ๋‹ค์‹œ ์‹œ์ž‘
systemctl restart docker


#์‚ฌ์šฉ์ž ์ง€์ • ์ธ์ฆ์„œ ์‚ฌ์šฉ ๊ตฌ์„ฑ
/etc/docker/certs.d/
    โ””โ”€โ”€ yourdomain.com:port
       โ”œโ”€โ”€ yourdomain.com.cert  <-- Server certificate signed by CA
       โ”œโ”€โ”€ yourdomain.com.key   <-- Server key signed by CA
       โ””โ”€โ”€ ca.crt               <-- Certificate authority that signed the registry certificate
Harbor Reorganization
bash
# ์ด๋ฏธ HTTP๋กœ Harbor๋ฅผ ๋ฐฐํฌํ–ˆ์œผ๋ฉฐ HTTPS๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ์žฌ๊ตฌ์„ฑํ•˜๋ ค๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ์ˆ˜ํ–‰ํ•˜์‹ญ์‹œ์˜ค.

# prepare์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜์—ฌ HTTPS๋ฅผ ํ™œ์„ฑํ™”ํ•˜์‹ญ์‹œ์˜ค.
# Harbor๋Š” nginx์ธ์Šคํ„ด์Šค๋ฅผ ๋ชจ๋“  ์„œ๋น„์Šค์— ๋Œ€ํ•œ ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. prepare์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ HTTPS๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ๊ตฌ์„ฑ ํ•ฉ๋‹ˆ๋‹ค nginx. ์Šคํฌ๋ฆฝํŠธ prepare์™€ ๋™์ผํ•œ ์ˆ˜์ค€์˜ Harbour ์„ค์น˜ ํ”„๋กœ๊ทธ๋žจ ๋ฒˆ๋“ค์— ์žˆ์Šต๋‹ˆ๋‹ค .install.sh
./prepare

# Harbor๊ฐ€ ์‹คํ–‰ ์ค‘์ธ ๊ฒฝ์šฐ ๊ธฐ์กด ์ธ์Šคํ„ด์Šค๋ฅผ ์ค‘์ง€ํ•˜๊ณ  ์ œ๊ฑฐํ•˜์‹ญ์‹œ์˜ค.
# ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ๋Š” ํŒŒ์ผ ์‹œ์Šคํ…œ์— ๋‚จ์•„ ์žˆ์œผ๋ฏ€๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ์†์‹ค๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
docker-compose down -v

# ํ•˜๋ฒ„ ์žฌ์‹œ์ž‘
docker-compose up -d
Check HTTPS connection

After you set up HTTPS for Harbor, you can verify HTTPS connectivity by performing the following steps:

  • Open your browser and type https://yourdomain.com.ย You should see the Harbor interface.

    Some browsers may display a warning that the Certificate Authority (CA) is unknown.ย This happens when you use a self-signed CA rather than a trusted third-party CA.ย You can remove the warning by importing the CA into your browser.

  • Check the /etc/docker/daemon.json file on the system running the Docker daemon to ensure that the option for https://yourdomain.cominsecure-registry is not set.

  • Log in to Harbor from your Docker client.

    docker login yourdomain.com

If you have mapped port 443 to another port, add the port to the command nginx.login

docker login yourdomain.com:port

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *