Docker安装habor

habor版本:https://github.com/goharbor/harbor/releases/tag/v2.4.0

docker、新兴技术能力Docker安装habor插图

首先下载压缩包

第一步:安装docker-compose

http://www.fcors.com/%e6%8a%80%e6%9c%af%e4%b8%8e%e6%a1%86%e6%9e%b6/%e6%96%b0%e5%85%b4%e6%8a%80%e6%9c%af%e8%83%bd%e5%8a%9b/dockercompose/

第二步:复制压缩包到宿主机上

shell>tar zxvf harbor-offline-installer-v2.0.0.tgz
shell>cd harbor
shell>cp harbor.yml.tmpl harbor.yml
shell>vim harbor.yml
----设置hostname和屏蔽https
docker、新兴技术能力Docker安装habor插图1
shell> ./prepare
shell>  ./install.sh
====================
如果出现报错:Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /var/log/harbor/
则
shell>mkdir /var/log/harbor/
shell>docker-compose up -d

harbor的初始账号和密码是:admin/Harbor12345

第三步:上传镜像

shell>docker login http://192.168.8.31:8088/
====输入账号密码后
Error response from daemon: Get "https://192.168.8.31:8088/v2/": http: server gave HTTP response to HTTPS client
为什么呢?因为docker login是https的,这个没有配置https,所以需要设置docker信任

3.1 设置docker信任

shell>vi /etc/docker/daemon.json
====添加 insecure-registries 可以用过docker info 查看
{"insecure-registries":["192.168.8.31:8088"]}
shell> systemctl restart docker
shell>docker-compose up -d
shell>echo -n Harbor12345 | docker login -u admin --password-stdin http://192.168.8.31:8088

3.2 设置镜像Tag

shell>docker tag SOURCE_IMAGE[:TAG] 192.168.8.31:8088/library/REPOSITORY[:TAG]
shell>docker push 192.168.8.31:8088/library/REPOSITORY[:TAG]
docker、新兴技术能力Docker安装habor插图2

如何harbor配置https

1、生成ssl证书

2、Harbor启用HTTPS

# vi harbor.yml
https:
port: 443
certificate: /root/harbor/ssl/reg.ctnrs.com.pem
private_key: /root/harbor/ssl/reg.ctnrs.com-key.pem

3、重新启动harbor

shell>./prepare
shelldocker-compose down
shelldocker-compose up –d

4、将数字证书复制到其他主机

shll>mkdir /etc/docker/certs.d/reg.ctnrs.com
shell>cp reg.ctnrs.com.pem /etc/docker/certs.d/reg.ctnrs.com/reg.ctnrs.com.crt