Docker镜像仓库Harbor安装与配置

Harbor简介:
Docker容器应用的开发和运行离不开可靠的镜像管理,虽然Docker官方也提供了公共的镜像仓库,但是从安全和效率等方面考虑,部署我们私有环境内的Registry也是非常必要的。Harbor是由VMware公司开源的企业级的Docker Registry管理项目,它包括权限管理(RBAC)、LDAP、日志审核、管理界面、自我注册、镜像复制和中文支持等功能。

Harbor下载:
国外下载地址:https://github.com/goharbor/harbor/releases
国内下载地址:http://harbor.orientsoft.cn/
docker-compose,下载地址,https://github.com/docker/compose/releases

注:Harbo需要安装docker,及docker-compose,安装方法这里不再细说。

1、解压及修改配置文件

# tar zxvf harbor-offline-installer-v1.5.1.tgz
# cd harbor
# vim harbor.cfg

根据需要配置相应的访问ip,密码等

2、准备配置文件

# ./prepare

3、安装
# ./install.sh

安装成功后,访问配置ip即可
Docker镜像仓库Harbor安装与配置

4、端口修改
因为harbor默认端口为80,而大多数时候是不希望使用80端口的,修改端口方法如下:
在harbor目录下
(1)、修改docker-compose.yml文件

# vim docker-compose.yml

proxy:
    image: vmware/nginx-photon:v1.5.1
    container_name: nginx
    restart: always
    volumes:
      - ./common/config/nginx:/etc/nginx:z
    networks:
      - harbor
    ports:
      - 8070:80
      - 443:443

(2)\修改common/templates/registry/config.yml文件

扫描二维码关注公众号,回复: 2926614 查看本文章
# vim common/templates/registry/config.yml
auth:
  token:
    issuer: harbor-token-issuer
    realm: $public_url:8070/service/token
    rootcertbundle: /etc/registry/root.crt
service: harbor-registry

5、镜像推送
# docker login 192.168.xxx.xx:xx

镜像打包时候需要按一定规则tag

# docker tag mysql 192.168.100.127:8070/test/mysql_test
# docker pull 192.168.100.127:8070/test/mysql_test

游览器打开Harbor即可看到推送的镜像~

备注:
若推送镜像报以下错误:

Error response from daemon: Get https://192.168.100.xxx/v1/users/: http: server gave HTTP response to HTTPS client

原因为,docker默认使用的是https协议,而搭建的Harbor是http提供服务的,所以要配置可信任。PS:如果Harbor是https的就不会报该错误。

方法1、修改docker配置文件:

# vim /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd --insecure-registry=192.168.100.127:8070

修改完毕后按安装步骤走一遍即可。

方法2、

# vim /etc/docker/daemon.json

{
 "registry-mirrors": ["http://xxx0.m.daocloud.io"]
 "insecure-registries":["192.168.100.127:8070"]
}    

配置完以后重启一下docker

6、删除镜像及垃圾回收:

若知识在Harbor客户端删除,只是删除了标记,存储文件仍然存在,删除实际的文件存储库使用注册中心的垃圾收集(GC)。GC运行时如果有人推一个镜像,还存在一种风险,即镜像的层将被错误删除导致镜像损坏。在GC运行之前,首选的方法是先停止Harbor

# docker-compose stop

# docker run -it --name gc --rm --volumes-from registry goharbor/registry:2.6.2-photon garbage-collect --dry-run /etc/registry/config.yml

# docker-compose stop

官方用户手册:
https://github.com/goharbor/harbor/blob/master/docs/user_guide.md

猜你喜欢

转载自blog.51cto.com/bilibili/2165513