1 官方仓库构建
1.1 仓库服务器的配置
docker run -d -v /var/docker/registry:/var/lib/registry -p 5000:5000 --restart=always registry
vim /etc/docker/daemon.json{"registry-mirrors": ["https://du3ia00u.mirror.aliyuncs.com"],"insecure-registries": ["192.168.179.100:5000"]}systemctl daemon-reloadsystemctl restart docker
192.168.179.100是仓库服务器的地址。
- 验证是否安装成功:
http://192.168.179.100:5000/v2/

- 从Docker Hub上拉取镜像:
docker pull hello-world
- 将拉取到本地的镜像改为ip地址:端口号/用户名/镜像名称:标签:
docker tag hello-world:latest 192.168.179.100:5000/hello-world:v1.0
- 推送镜像到本地仓库:
docker push 192.168.179.100:5000/hello-world:v1.0

1.2 客户端设置
vim /etc/docker/daemon.json{"registry-mirrors": ["https://du3ia00u.mirror.aliyuncs.com"],"insecure-registries": ["192.168.179.100:5000"]}systemctl daemon-reloadsystemctl restart docker
docker pull 192.168.179.100:5000/hello-world:v1.0
2 Harbor仓库构建
2.1 安装底层需求
- Python应该为2.7或更高版本。
- Docker引擎应该为1.10或更高版本。
- Docker Compose应该为1.6.0或更高版本。
2.2 Harbor的安装
2.2.1 解压压缩包
wget https://github.com/goharbor/harbor/releases/download/v1.2.0/harbor-offline-installer-v1.2.0.tgz
tar -zxvf harbor-offline-installer-v1.2.0.tgz

2.2.2 移动harbor到/usr/local目录下
mv harbor /usr/local

2.2.3 创建https证书以及配置相关目录权限
openssl genrsa -des3 -out server.key 2048

openssl req -new -key server.key -out server.csr

cp server.key server.key.org

openssl rsa -in server.key.org -out server.key

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

mkdir -pv /data/cert

chmod -R 777 /data/cert

mv server.* /data/cert/

2.2.4 修改harbor.cfg配置文件
cd /usr/local/harbor
vim harbor.cfghostname = hub.sunxiaping.comui_url_protocol = https

2.2.5 安装
- 在/usr/local/harbor目录下执行如下的命令:
./install.sh

2.3 Harbor的访问测试
- 在浏览器中输入https://192.168.64.100/harbor/sign-in,并输入admin/Harbor12345进行登录。

2.4 Harbor指定镜像仓库的地址
vim /etc/docker/daemon.json{"registry-mirrors": ["https://du3ia00u.mirror.aliyuncs.com"],"insecure-registries": ["192.168.64.100","hub.sunxiaping.com"]}systemctl daemon-reloadsystemctl restart docker
vim /etc/hosts192.168.64.100 hub.sunxiaping.com
2.5 Harbor下载测试镜像
docker pull hello-world
2.6 Harbor给镜像重新打上标签
docker tag hello-world:latest hub.sunxiaping.com/sy/hello-world:v1.0
2.7 Harbor登录
docker login 192.168.64.100或docker login hub.sunxiaping.com
2.8 Harbor推送镜像
docker push hub.sunxiaping.com/sy/hello-world:v1.0

2.9 其他Docker客户端下载镜像
2.9.1 指定镜像仓库地址
vim /etc/docker/daemon.json{"registry-mirrors": ["https://du3ia00u.mirror.aliyuncs.com"],"insecure-registries": ["192.168.64.100","hub.sunxiaping.com"]}systemctl daemon-reloadsystemctl restart docker
vim /etc/hosts192.168.64.100 hub.sunxiaping.com
2.9.2 登录
docker login 192.168.64.100或docker login hub.sunxiaping.com
2.9.3 下载镜像
docker pull hub.sunxiaping.com/sy/hello-world:v1.0
