Deploying Harbor and Nexus for Container Images and Maven Artifacts

At least 4-core CPU and 4 GB RAM. Install Docker and Docker Compose first.

Harbor Registry Setup

# Download the offline installer and extract
tar -zxvf harbor-offline-installer-v2.4.1.tgz -C /usr/local/
cd /usr/local/harbor/
cp harbor.yml.tmpl harbor.yml

# Edit harbor.yml: set hostname to your IP, comment out HTTPS block, update admin password
vim harbor.yml

# Install
./install.sh

# After system reboot, stop and restart services
docker-compose down -v
docker-compose up -d

Docker Client Configuration

vim /etc/docker/daemon.json
{
   "insecure-registries" : ["192.168.44.22"]
}

systemctl restart docker
docker login 192.168.44.22 -u admin -p Harbor12345

Kubernetes Integration

Create a registry secret:

kubectl create secret docker-registry docker-registry-secret \
  --namespace=default \
  --docker-server=192.168.44.22 \
  --docker-username=test \
  --docker-password=123456 \
  --docker-email=test@qq.com

Verify secret creation:

kubectl get secret docker-registry-secret --output=yaml

Patch the default service account to automatically use the pull secret:

kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "docker-registry-secret"}]}'

Use the secret directly in a Pod spec:

apiVersion: v1
kind: Pod
metadata:
  name: private-reg
spec:
  containers:
  - name: private-reg-container
    image: <your-private-image>
  imagePullSecrets:
  - name: docker-registry-secret

Nexus Repository Setup

mkdir -p ~/nexus-data
chmod -R 777 ~/nexus-data

# 8081 for Maven, 8082 for Docker registry
docker run -d -p 8081:8081 -p 8082:8082 \
  --restart always --name nexus \
  -v ~/nexus-data:/nexus-data sonatype/nexus3

# Retrieve initial admin password
cat ~/nexus-data/admin.password

Maven Private Repository Configuration

  • Add an Alibaba Cloud proxy: http://maven.aliyun.com/nexus/content/groups/public
  • Create a maven-public group that merges proxy and hosted repos.
  • Create maven-releases hosted repository with deployment permission.
  • Create a dedicated user with approrpiate privileges.

Maven Settings (settings.xml)

<?xml version="1.0" encoding="UTF-8"?>
<settings>
  <localRepository>D:/develop/maven-nexus-lib</localRepository>
  <servers>
    <server>
      <id>maven-releases</id>
      <username>test</username>
      <password>123456</password>
    </server>
    <server>
      <id>maven-snapshots</id>
      <username>test</username>
      <password>123456</password>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://192.168.44.22:8081/repository/maven-public/</url>
    </mirror>
  </mirrors>
</settings>

Project pom.xml Deployment

<distributionManagement>
  <repository>
    <id>maven-releases</id>
    <name>maven-releases</name>
    <url>http://192.168.44.22:8081/repository/maven-releases/</url>
  </repository>
  <snapshotRepository>
    <id>maven-snapshots</id>
    <name>maven-snapshots</name>
    <url>http://192.168.44.22:8081/repository/maven-snapshots/</url>
  </snapshotRepository>
</distributionManagement>

<repositories>
  <repository>
    <id>maven-snapshots</id>
    <url>http://192.168.44.22:8081/repository/smart_group/</url>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </repository>
</repositories>

Disk Space Recovery for Harbor

When images fill up the disk, perform an aggressive cleanup:

# Stop Harbor
docker-compose down

# Remove all blob data
cd /data/registry/docker/registry/v2/blobs/sha256/
rm -rf ./*

# Restart
docker-compose up -d

After restart, trigger garbage collection from the Harbor UI. Because blobs were manually deleted, you must run GC immediately to fix metadata and allow image pulls again.

Tags: harbor Nexus kubernetes Maven docker-registry

Posted on Tue, 13 Oct 2026 16:28:24 +0000 by ol4pr0