背景:需要主机安装docker-ce和docer-compose
#1.安装相关依赖.
yum install -y yum-utils device-mapper-persistent-data lvm2
#2.下载官方的docker yum源文件
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#3.替换yum源地址
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
#4.安装docker-ce
yum makecache fast
yum -y install docker-ce docker-compose
systemctl enable --now docker
#检查
docker version
开启镜像下载加速
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<'EOF'
{
"registry-mirrors": ["https://bjjtv7cs.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
1. 主库harbor配置
1.1. 修改所有docker机器的hosts解析
vim /etc/hosts
10.0.0.81 docker01.tom.cn
10.0.0.82 docker02.tom.cn harbor.tom.cn
1.2. 下载解压:
https://github.com/goharbor/harbor/releases/download/v2.11.0/harbor-offline-installer-v2.11.0.tgz
mkdir -p /app/tools/
tar -xvf harbor-offline-installer-v2.11.0.tgz -C /app/tools
cd /app/tools/harbor
harbor]# tree .
.
├── common.sh
├── harbor.v2.11.0.tar.gz
├── harbor.yml.tmpl #临时配置文件 正式配置文件叫harbor.yml
├── install.sh #每次修改配置 需要执行下
├── LICENSE
└── prepare
1.3. 修改配置文件
cp harbor.yml.tmpl harbor.yml
vim harbor.yml
#修改域名
hostname: harbor.tom.cn
#注释掉证书配置
#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: Admin
1.4. 安装
./install.sh
#注意要检查80是否被占用
提示successfully
? ----Harbor has been installed and started
successfully.----
成功
需要安装docker和docker-compose
1.5. 浏览器访问
1.6. 修改所有docker私有仓库地址为harbor网址
# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://bjjtv7cs.mirror.aliyuncs.com"],
"insecure-registries": ["harbor.tom.cn"]
}
systemctl restart docker
1.7. 往仓库推送镜像
#打tag
docker tag nginx:alpine harbor.tom.cn/library/nginx-alpine:v1
#push到仓库
docker push harbor.tom.cn/library/nginx-alpine:v1
1.8. 别的机器下载测试
docker pull harbor.tom.cn/library/nginx-alpine:v1