目录
系统环境:
安装Docker-Compose
下载并安装Harber
启动Harbor
使用Harbor
上传下载镜像到harbor仓库
系统环境:
- Centos7.9
- Docker-ce:24
安装Docker-Compose
curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
添加执行权限并验证
[root@node4 ~]# chmod +x /usr/local/bin/docker-compose
[root@node4 ~]# docker-compose --version
Docker Compose version v2.20.3
下载并安装Harber
#下载harbor
wget https://github.com/goharbor/harbor/releases/download/v2.8.4/harbor-offline-installer-2.8.4.tgz
#解压
tar -xzf harbor-offline-installer-v2.8.4.tgz -C /usr/local/
修改配置文件
[root@node4 ~]# cd /usr/local/harbor/
[root@node4 harbor]# ll
total 597560
drwxr-xr-x 3 root root 20 Aug 20 07:04 common
-rw-r--r-- 1 root root 3639 Aug 15 17:53 common.sh
-rw-r--r-- 1 root root 5834 Aug 20 07:07 docker-compose.yml
-rw-r--r-- 1 root root 611834153 Aug 15 17:54 harbor.v2.8.4.tar.gz
-rw-r--r-- 1 root root 12492 Aug 20 07:03 harbor.yml
-rw-r--r-- 1 root root 12499 Aug 15 17:53 harbor.yml.tmpl
-rwxr-xr-x 1 root root 2725 Aug 15 17:53 install.sh
-rw-r--r-- 1 root root 11347 Aug 15 17:53 LICENSE
-rwxr-xr-x 1 root root 1881 Aug 15 17:53 prepare
[root@node4 harbor]# vim harbor.yml
主要修改了: hostname:主机名
max_job_workers:最大cpu数,小于等于自己服务器的硬件
注释掉了https related config里面的内容
启动Harbor
[root@node4 harbor]# ./install.sh
使用Harbor
浏览器访问:ip:/harbor/sign-in
使用admin登录,密码为Harbor12345(初始密码在harbor.cfg 文件有记录)
新建一个项目
上传下载镜像到harbor仓库
修改docker配置,添加harbor仓库为信任地址
[root@node4 harbor]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://9qawopss.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.80.135:5000"],
"insecure-registries": ["docker:80"]
}
[root@node4 harbor]# systemctl restart docker
#手动启动harbor
[root@node4 harbor]# docker-compose up -d
[root@node4 harbor]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.80.135 docker #添加解析
把要上传的镜像打上合适的标签
[root@node4 harbor]# docker tag busybox:latest docker:80/demo/busybox:v0.1
[root@node4 harbor]# docker images | grep demo
docker:80/demo/busybox v0.1 beae173ccac6 19 months ago 1.24MB
登录harbor仓库
[root@node4 harbor]# docker login docker:80
Username (admin): admin
Password:
Login Succeeded
上传镜像
[root@node4 harbor]# docker push docker:80/demo/busybox:v0.1
The push refers to repository [docker:80/demo/busybox]
01fd6df81c8e: Pushed
v0.1: digest: sha256:62ffc2ed7554e4c6d360bce40bbcf196573dd27c4ce080641a2c59867e732dee size: 527
在harbor上验证上传成功
拉取harbor中的镜像
[root@node4 harbor]# docker rmi docker:80/demo/busybox:v0.1
Untagged: docker:80/demo/busybox:v0.1
Untagged: docker:80/demo/busybox@sha256:62ffc2ed7554e4c6d360bce40bbcf196573dd27c4ce080641a2c59867e732dee
[root@node4 harbor]# docker pull docker:80/demo/busybox:v0.1
v0.1: Pulling from demo/busybox
Digest: sha256:62ffc2ed7554e4c6d360bce40bbcf196573dd27c4ce080641a2c59867e732dee
Status: Downloaded newer image for docker:80/demo/busybox:v0.1
docker:80/demo/busybox:v0.1
#验证拉取成功没
[root@node4 harbor]# docker images | grep demo
docker:80/demo/busybox v0.1 beae173ccac6 19 months ago 1.24MB