1. Harbor搭建
Harbor官方文档:https://github.com/goharbor/harbor
1.下载Docker的单机编排工具(Docker compose),安装需添加docker-ce.repo源
[root@node02 ~]# yum -y install docker-compose
[root@node02 ~]# cd /usr/src/
2.下载Harbor
[root@node02 src]# wget https://github.com/goharbor/harbor/releases/download/v1.10.2/harbor-offline-installer-v1.10.2.tgz
[root@node02 src]# ls
debug harbor-offline-installer-v1.10.1.tgz kernels
3.解压Harbor
[root@node02 src]# tar xf harbor-offline-installer-v1.10.1.tgz -C /usr/local/
[root@node02 src]# ls /usr/local/
bin etc games harbor include lib lib64 libexec sbin share src
[root@node02 src]# cd /usr/local/harbor/
[root@node02 harbor]# ls
common.sh harbor.v1.10.1.tar.gz harbor.yml install.sh LICENSE prepare
4.修改配置
[root@node02 harbor]# vim harbor.yml
...
hostname: node02-linux.example.com #修改hostname为当前主机名
#若无HTTPS证书可注释以下几行
# https:
# https port for harbor, default is 443
# port: 443
# The path of cert and key files for nginx
# certificate: /your/certificate/path
# private_key: /your/private/key/path
harbor_admin_password: harbor123456 #在此修改harbor的admin管理员登录密码
# Harbor DB configuration
database:
# The password for the root user of Harbor DB. Change this before any production use.
password: root123456 #数据库密码
...
5.执行安装脚本,安装后使用80端口和1514端口
[root@node02 harbor]# ./install.sh
[root@node02 harbor]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:1514 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22
2. harbor操作
启动Harbor
[root@reg ~]# docker-compose start
2.1 harbor访问
在主机ip后加/harbor即可访问,用户名为admin,密码在配置中已设置
2.2 上传镜像
2.2.1 创建项目
2.2.2 上传镜像
1. 点击项目名称进入项目,点击镜像仓库,可点击推送镜像的DOCKER命令查看
2. 在主机中登录docker用户
[root@reg harbor]# docker login reg.docker.com
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
3. 修改镜像tag
[root@reg harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd v0.3 8c73b3847188 12 hours ago 187MB
[root@reg harbor]# docker tag httpd:v0.3 reg.docker.com/docker/httpd:v0.1
[root@reg harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd v0.3 8c73b3847188 12 hours ago 187MB
reg.docker.com/docker/httpd v0.1 8c73b3847188 12 hours ago 187MB
4. 添加搭建的Harbor加速器,地址为harbor主机名
[root@reg harbor]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["http://reg.docker.com"],
"registry-mirrors": ["https://41c6gj8l.mirror.aliyuncs.com"]
}
[root@reg harbor]# systemctl restart docker
[root@reg harbor]# docker-compose stop
Stopping harbor-jobservice ... done
Stopping nginx ... done
Stopping harbor-core ... done
Stopping harbor-db ... done
Stopping redis ... done
Stopping harbor-portal ... done
Stopping registryctl ... done
Stopping registry ... done
Stopping harbor-log ... done
[root@reg harbor]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
[root@reg harbor]# docker-compose start
Starting log ... done
Starting registry ... done
Starting registryctl ... done
Starting postgresql ... done
Starting portal ... done
Starting redis ... done
Starting core ... done
Starting jobservice ... done
Starting proxy ... done
[root@reg harbor]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:1514 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 [::]:80 [::]:*
5. 上传镜像
[root@reg src]# docker push reg.docker.com/docker/httpd:v0.1
[root@reg harbor]# docker push reg.docker.com/docker/httpd:v0.1
The push refers to repository [reg.docker.com/docker/httpd]
85af3fcfec43: Mounted from harbor/httpd
6daf13eee9fd: Mounted from harbor/httpd
beee9f30bc1f: Mounted from harbor/httpd
v0.1: digest: sha256:fbd88b62c5b2ce1bab362919662429ee14bb9081231d967638d77b0f28033bbb size: 951
6. 查看项目中镜像是否上传