0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Harbor registryの構築手順

Posted at

1. はじめに

Harbor registryの構築手順

2. 前提条件

  • Ubuntu 24.04
  • Docker 28.1.1

3. 構築手順

3.1. 名前解決

Harborのホスト名を設定する

$ cat /etc/hosts
192.168.1.24   harbor.home.internal

3.2. Harborのダウンロード

作業ディレクトリを作成し、Harbor のオンラインインストーラーをダウンロードする。

$ mkdir harboar
$ cd harbor
$ wget https://github.com/goharbor/harbor/releases/download/v2.12.4/harbor-online-installer-v2.12.4.tgz
$ ls
harbor-online-installer-v2.12.4.tgz

3.3. 証明書作成

HTTPSでアクセスするために、自己署名証明書を作成する。

## 証明書用ディレクトリの作成
$ mkdir cert
$ cd cert

## CA証明書の作成
$ openssl genrsa -out ca.key 4096
$ openssl req -x509 -new -nodes -sha512 -days 3650 \
 -subj "/CN=CA" \
 -key ca.key \
 -out ca.crt

## Harborサーバー証明書の作成
$ openssl genrsa -out harbor.key 4096
$ openssl req -sha512 -new \
    -subj "/CN=harbor.home.internal" \
    -key harbor.key \
    -out harbor.csr
$ cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

[alt_names]
DNS.1=harbor.home.internal
DNS.2=harbor
EOF
$ openssl x509 -req -sha512 -days 3650 \
    -extfile v3.ext \
    -CA ca.crt -CAkey ca.key -CAcreateserial \
    -in harbor.csr \
    -out harbor.crt
Certificate request self-signature ok
subject=CN = harbor.home.internal

## 作成されたファイルの確認
$ ls
ca.crt  ca.key  ca.srl  harbor.crt  harbor.csr  harbor.key  v3.ext

3.4. Harbor設定

Harborのインストーラーを展開し、設定ファイルを編集する。

$ cd ..
$ tar zxvf harbor-online-installer-v2.12.4.tgz
$ cd harbor

## データとログ用のディレクトリ作成
$ mkdir data
$ mkdir log

## 設定ファイルの作成
$ cp harbor.yml.tmpl harbor.yml
$ vi harbor.yml

設定ファイルは以下を変更する。

# ホスト名の設定
hostname: harbor.home.internal

# HTTPS の設定
https:
  certificate: /harbor/cert/harbor.crt
  private_key: /harbor/cert/harbor.key

# データボリュームの設定
data_volume: ./data

# ログの設定
log:
  local:
    location: ./log

3.5. Harborのインストール

インストールスクリプトを実行する。

$ sudo ./prepare
$ sudo ./install.sh

## インストール完了後、コンテナの状態を確認
$ sudo docker compose ps
NAME                IMAGE                                 COMMAND                  SERVICE       CREATED          STATUS                             PORTS
harbor-core         goharbor/harbor-core:v2.12.4          "/harbor/entrypoint.…"   core          29 seconds ago   Up 28 seconds (health: starting)
harbor-db           goharbor/harbor-db:v2.12.4            "/docker-entrypoint.…"   postgresql    29 seconds ago   Up 29 seconds (health: starting)
harbor-jobservice   goharbor/harbor-jobservice:v2.12.4    "/harbor/entrypoint.…"   jobservice    29 seconds ago   Up 24 seconds (health: starting)
harbor-log          goharbor/harbor-log:v2.12.4           "/bin/sh -c /usr/loc…"   log           30 seconds ago   Up 29 seconds (health: starting)   127.0.0.1:1514->10514/tcp
harbor-portal       goharbor/harbor-portal:v2.12.4        "nginx -g 'daemon of…"   portal        29 seconds ago   Up 29 seconds (health: starting)
nginx               goharbor/nginx-photon:v2.12.4         "nginx -g 'daemon of…"   proxy         29 seconds ago   Up 28 seconds (health: starting)   0.0.0.0:80->8080/tcp, [::]:80->8080/tcp, 0.0.0.0:443->8443/tcp, [::]:443->8443/tcp
redis               goharbor/redis-photon:v2.12.4         "redis-server /etc/r…"   redis         29 seconds ago   Up 29 seconds (health: starting)
registry            goharbor/registry-photon:v2.12.4      "/home/harbor/entryp…"   registry      29 seconds ago   Up 29 seconds (health: starting)
registryctl         goharbor/harbor-registryctl:v2.12.4   "/home/harbor/start.…"   registryctl   29 seconds ago   Up 29 seconds (health: starting)
ubuntu@ubuntu:~/harbor/harbor$

3.6. 動作確認

Harborログイン確認

## CA証明書をシステムの信頼済み証明書に追加
$ sudo cp ../cert/ca.crt /usr/local/share/ca-certificates/
$ sudo update-ca-certificates

## docker loginでHarborにログイン
$ docker login harbor.home.internal
Username: admin
Password:

WARNING! Your credentials are stored unencrypted in '/home/xxxxx/.docker/config.json'.
Configure a credential helper to remove this warning. See
https://docs.docker.com/go/credential-store/

Login Succeeded

イメージのプッシュ確認

プロジェクトを作成

  1. ブラウザから、https://harbor.home.internalにアクセスする
  2. adminでログインする
  3. 「New Project」からtestプロジェクトを作成

2025-05-24-22-33-11.png

テスト用イメージをpushする

$ sudo docker pull nginx:latest
$ sudo docker tag nginx:latest harbor.home.internal/test/nginx:latest
$
$ sudo docker push harbor.home.internal/test/nginx:latest
The push refers to repository [harbor.home.internal/test/nginx]
941dd9dd8ee4: Pushed
f6e33ee35fd0: Pushed
9fd8b974f616: Pushed
a8b606cdf152: Pushed
cb857378ec55: Pushed
deb7d8874f38: Pushed
ace34d1d784c: Pushed
latest: digest: sha256:e5e2c4be5cea9bf49b2c976c65b4fca33d9d094b276a5e517d8e5748100a3c73 size: 1778
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?