build with harbor
大约 5 分钟
build with harbor
1 Private Docker Registry Selection
https://supereagle.github.io/2019/11/23/harbor-vs-quay/
Harbor Installation and Configuration
2本章全程参考官网给出的手册
Prerequisites
2.1Software | Version | Description |
---|---|---|
Docker Engine | Version 20.10.10-ce+ or higher | For installation instructions, see Docker Engine documentation |
Docker Compose | docker-compose (v1.18.0+) or docker compose v2 (docker-compose-plugin) | For installation instructions, see Docker Compose documentation |
OpenSSL | Latest is preferred | Used to generate certificate and keys for Harbor |
docker engine和docker compose可以通过docker desktop安装,以下适用于ubuntu 22.04
install docker desktop on ubuntu
2.1.1install using the apt repository
2.1.1.1官网提供的源对国内用户不友好,以下使用阿里的docker镜像仓库证书
2.1.1.1.1 安装设置仓库必须的工具
sudo apt update && sudo apt install -y ca-certificates curl gnupg lsb-release
2.1.1.1.2 添加阿里的 Docker 镜像仓库证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/aliyun-docker.gpg
2.1.1.1.3 添加仓库
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/aliyun-docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
DEB package
2.1.1.2 Download latest2.1.1.3 Install the package with apt as follows
sudo apt-get update
sudo apt-get install ./docker-desktop-<arch>.deb
2.1.2 launch docker desktop
systemctl --user start docker-desktop
systemctl --user enable docker-desktop
2.1.3 check the versions
docker compose version
docker --version
docker version
Client: Docker Engine - Community
Version: 27.1.2
API version: 1.46
Go version: go1.21.13
Git commit: d01f264
Built: Mon Aug 12 11:50:12 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 27.1.2
API version: 1.46 (minimum version 1.24)
Go version: go1.21.13
Git commit: f9522e5
Built: Mon Aug 12 11:50:12 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.7.20
GitCommit: 8fc6bcff51318944179630522a095cc9dbf9f353
runc:
Version: 1.1.13
GitCommit: v1.1.13-0-g58aa920
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Download the Harbor Installer
2.2https://github.com/goharbor/harbor/releases
tar xzvf harbor-offline-installer-version.tgz
Configure the Harbor YML File
2.3cd harbor
cp harbor.yml.tmpl harbor.yml
# 修改hostname为本机ip,如192.168.2.248
# 修改http port为想要开放的端口,如30080
# 注释https相关字段,暂时不考虑安全认证
# 可以留意到harbor_admin_password默认为Harbor12345
vi harbor.yml
Run the Installer Script
2.4./install.sh
2.4.1 Connecting to Harbor via HTTP
2.4.1.1 Restart Docker Engine
systemctl daemon-reload
systemctl restart docker
2.4.1.2 Stop Harbor
docker compose down -v
2.4.1.1 Restart Harbor
docker compose up -d
3 Startup service
3.1 configure service
vi /etc/systemd/system/harbor.service
[Unit]
Description=Start Harbor after Docker
After=docker.service
Requires=docker.service
[Service]
Type=oneshot
ExecStart=/home/cltech/zihu/harbor/install.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
3.2 start service
sudo systemctl daemon-reload
sudo systemctl enable harbor.service
sudo systemctl start harbor.service
3.3 query service
sudo systemctl status harbor.service
4 private docker registry
4.1 registry URL
http://192.168.2.248:30080
admin
Harbor12345
4.2 configure docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://docker.m.daocloud.io"
"https://docker.mirrors.ustc.edu.cn",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://ccr.ccs.tencentyun.com"
],
"insecure-registries": ["192.168.2.248:30080"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
4.3 push images
docker images
docker tag d2c94e258dcb 192.168.2.248:30080/driver/hello-world:1.0
docker login -u admin -p Harbor12345 192.168.2.248:30080
docker push 192.168.2.248:30080/driver/hello-world:1.0

4.4 pull images
docker pull 192.168.2.248:30080/driver/hello-world:1.0
5 过程踩到的坑
5.1 docker daemon没有拉起来?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
systemctl status docker.service
journalctl -xeu docker.service
出问题了请先查docker logs
这次遇到的问题是和iptables相关,解决办法是
update-alternatives --set iptables /usr/sbin/iptables-legacy