将你自定义的harbor地址写到需要登陆的服务器hosts

echo "192.168.1.1  docker.harbor.com" >> /etc/hosts 

安装docker 移除旧的docker 依赖

 sudo yum remove docker \
 docker-client \
 docker-client-latest \
 docker-common \
 docker-latest \
 docker-latest-logrotate \
 docker-logrotate \
 docker-engine

设置docker 源

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager  --add-repo  https://download.docker.com/linux/centos/docker-ce.repo

安装docker

sudo yum -y install docker-ce docker-ce-cli containerd.io

启动

systemctl enable docker && systemctl start docker

安装docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.26.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

修改权限

sudo chmod +x /usr/local/bin/docker-compose

查看版本

docker-compose --version

安装harbor

wget https://github.com/goharbor/harbor/releases/download/v2.2.0-rc1/harbor-offline-installer-v2.2.0-rc1.tgz

解压

tar xvf harbor-offline-installer-v2.2.0-rc1.tgz

创建目录 添加密钥(密钥的harbor地址要和hosts地址相同)

mkdir /etc/certs && cd  /etc/certs
openssl genrsa -out /etc/certs/ca.key 2048
openssl req -x509 -new -nodes -key /etc/certs/ca.key -subj "/CN=docker.harbor.com" -days 5000 -out /etc/certs/ca.crt

修改配置

cp harbor.yml.tmpl harbor.yml && vim harbor.yml
hostname: docker.harbor.com  
https:                  
port: 443             
certificate: /etc/certs/ca.crt            
private_key: /etc/certs/ca.key       
harbor_admin_password:123456

Harbor登录用户admin 密码123456(自行修改 )

安装harbor

cd /harbor/
./install.sh

安装之后即可登录

Harbor服务器IP
https://192.168.1.1

搭建harbor2.2.0版本

客户端操作:

mkdir -p /etc/docker/certs.d/docker.harbor.con

服务端操作 :

scp /etc/certs/ca.crt root@192.168.1.1:/etc/docker/certs.d/docker.harbor.com/     
systemctl restart docker

测试登录harbor

docker login docker.harbor.com

如果登录提示:Error response from daemon: Get https://docker.harbor.com/v2/: x509: certificate signed by unknown authority
则有可能是有残留登录失败数据导致,需要编辑daemon.json ,指定你的登录地址

vi /etc/docker/daemon.json
{
    "insecure-registries": ["docker.harbor.com"]
}

重启docker 后登录即可

docker login 192.168.1.1
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

将下在好的或自己制作的镜像打上标签
注:标签要写harbor上传地址跟test_image自己创建的项目最后写镜像名称和版本

docker tag httpd:latest  docker.harbor.com/test_image/apache:v1

创建项目:
搭建harbor2.2.0版本
编辑项目
搭建harbor2.2.0版本

打好标签后进行上传

docker push docker.harbor.com/test/apache:v1

另一台下载测试

docker pull docker.harbor.com/test/apache:v1