Set Up Harbor in Alpine Linux

Set up Harbor in Alpine Linux

The steps here are adapted from here.

Pre-requisites

The Alpine Linux host must have the following:

  • Docker Engine
  • Docker Compose

The host should also have these supporting tools already installed:

  • curl
  • wget
  • tar
  • openssl

It should also run the bash shell as the harbor scripts work better.

Create Harbor Folder

mkdir -p /opt/harbor

Download and Extract Harbor

The full list of Harbor Releases can be found here.

I'm using the offline version of v2.14.4.

cd /opt

wget https://github.com/goharbor/harbor/releases/download/v2.14.4/harbor-offline-installer-v2.14.4.tgz
tar zvxf harbor-offline-installer-v2.14.4.tgz

Configure Harbor

cd /opt/harbor

cp harbor.yml.tmpl harbor.yml

Prepare certificates for harbor use. Place the .key and .crt in /etc/harbor/certs.

Edit harbor.yml. Minimally:

hostname: harbor.example.com

http:
  port: 80

https:
  port: 443
  certificate: /etc/harbor/certs/harbor.crt
  private_key: /etc/harbor/certs/harbor.key

harbor_admin_password: StrongPasswordHere

data_volume: /data

Generate Harbor Configuration

./prepare --with-trivy

Install Harbor

./install --with-trivy

Verify Containers

docker ps

You should see:

harbor-core
harbor-db
harbor-portal
harbor-jobservice
harbor-log
harbor-nginx
registry
registryctl
redis
trivy-adapter

Access Harbor

Navigate to https://harbor.example.com in your favourite browser.

The default login username is: admin

The password is whatever you have configured in the steps above.

Using Docker Client

docker login harbor.example.com

docker pull hello-world:latest
docker tag hello-world:latest harbor.example.com/library/hello-world:latest
docker push harbor.example/library/hello-world:latest

Managing Harbor

Start:

cd /opt/harbor
docker compose up -d

Stop:

cd /opt/harbor
docker compose down

Restart:

cd /opt/harbor
docker compose restart

View logs:

cd /opt/harbor
docker compose logs -f

Create an OpenRC Service

Create a new /etc/init.d/harbor file with the following contents:

#!/sbin/openrc-run

name="Harbor"
description="Harbor Registry"

depend() {
    need docker
}

start() {
    ebegin "Starting Harbor"
    cd /opt/harbor
    docker compose up -d
    eend $?
}

stop() {
    ebegin "Stopping Harbor"
    cd /opt/harbor
    docker compose down
    eend $?
}

Make executable:

chmod +x /etc/init.d/harbor

Enable service:

rc-update add harbor
rc-update -u

Start it immediately, if you want:

rc-service harbor start