企业实战(6)修改Harbor镜像仓库默认存储路径

相关文章:

 以下文章包含了Harbor镜像仓库搭建所需环境以及部署使用、报错解决。

Docker与Docker Engine部署:https://blog.csdn.net/qq_44895681/article/details/105540702

Docker-Compose部署:https://blog.csdn.net/qq_44895681/article/details/105540333

Harbor镜像仓库部署使用:https://blog.csdn.net/qq_44895681/article/details/105558611

命令行登录Harbor仓库报错解决:https://blog.csdn.net/qq_44895681/article/details/105573702

 Harbor安装后的默认存储路径是/data/。在一般的实际部署中大概率有修改的需求。

 如下图所示,根据宿主机根目录磁盘不同,默认的容量可能不满足需求:
企业实战(6)修改Harbor镜像仓库默认存储路径

环境介绍:

CentOS 7.5
Docker 19.03.8
Docker Engine 19.03.8
Docker-compose 1.25.4
Harbor 1.5.0

修改Harbor存储路径:

1.创建harbor存储目录:

[root@harbor ~]# cd /mnt/
[root@harbor mnt]# mkdir harbordata
[root@harbor ~]# cd /mnt/harbor
[root@harbor harbor]# docker-compose down -v   //停止并移除整个project的所有services
Stopping harbor-jobservice  ... done
Stopping nginx              ... done
Stopping harbor-ui          ... done
Stopping redis              ... done

2.修改harbor.cfg文件

[root@harbor harbor]# vim harbor.cfg     //修改harbor目录下harbor.cfg配置文件
secretkey_path = /mnt/harbordata      //更改harbor存储目录

3.修改docker-compose.yml文件

[root@harbor harbor]# vim docker-compose.yml   //修改harbor目录下docker-compose.yml
version: '2'
services:
  log:
    image: vmware/harbor-log:v1.5.0
    container_name: harbor-log
    restart: always
    volumes:
      - /var/log/harbor/:/var/log/docker/:z
      - ./common/config/log/:/etc/logrotate.d/:z
    ports:
      - 127.0.0.1:1514:10514
    networks:
      - harbor
  registry:
    image: vmware/registry-photon:v2.6.2-v1.5.0
    container_name: registry
    restart: always
    volumes:
      - /mnt/harbordata/registry:/storage:z      //更改harbor存储目录
      - ./common/config/registry/:/etc/registry/:z
    networks:
      - harbor
    environment:
      - GODEBUG=netdns=cgo
    command:
      ["serve", "/etc/registry/config.yml"]
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://127.0.0.1:1514"
        tag: "registry"
  mysql:
    image: vmware/harbor-db:v1.5.0
    container_name: harbor-db
    restart: always
    volumes:
      - /mnt/harbordata/database:/var/lib/mysql:z    //更改harbor存储目录
    networks:
      - harbor
    env_file:
      - ./common/config/db/env
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://127.0.0.1:1514"
        tag: "mysql"
  adminserver:
    image: vmware/harbor-adminserver:v1.5.0
    container_name: harbor-adminserver
    env_file:
      - ./common/config/adminserver/env
    restart: always
    volumes:
      - /mnt/harbordata/config/:/etc/adminserver/config/:z    //更改harbor存储目录
      - /mnt/harbordata/secretkey:/etc/adminserver/key:z     //更改harbor存储目录
      - /mnt/harbordata/:/data/:z        //更改harbor存储目录
    networks:
      - harbor
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://127.0.0.1:1514"
        tag: "adminserver"
  ui:
    image: vmware/harbor-ui:v1.5.0
    container_name: harbor-ui
    env_file:
      - ./common/config/ui/env
    restart: always
    volumes:
      - ./common/config/ui/app.conf:/etc/ui/app.conf:z
      - ./common/config/ui/private_key.pem:/etc/ui/private_key.pem:z
      - ./common/config/ui/certificates/:/etc/ui/certificates/:z
      - /mnt/harbordata/secretkey:/etc/ui/key:z    //更改harbor存储目录
      - /mnt/harbordata/ca_download/:/etc/ui/ca/:z    //更改harbor存储目录
      - /mnt/harbordata/psc/:/etc/ui/token/:z     //更改harbor存储目录
    networks:
      - harbor
    depends_on:
      - log
      - adminserver
      - registry
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://127.0.0.1:1514"
        tag: "ui"
  jobservice:
    image: vmware/harbor-jobservice:v1.5.0
    container_name: harbor-jobservice
    env_file:
- ./common/config/jobservice/env
    restart: always
    volumes:
      - /mnt/harbordata/job_logs:/var/log/jobs:z     //更改harbor存储目录
      - ./common/config/jobservice/config.yml:/etc/jobservice/config.yml:z
    networks:
      - harbor
    depends_on:
      - redis
      - ui
      - adminserver
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://127.0.0.1:1514"
        tag: "jobservice"
  redis:
    image: vmware/redis-photon:v1.5.0
    container_name: redis
    restart: always
    volumes:
      - /mnt/harbordata/redis:/data     //更改harbor存储目录
    networks:
      - harbor
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://127.0.0.1:1514"
        tag: "redis"
  proxy:
    image: vmware/nginx-photon:v1.5.0
    container_name: nginx
    restart: always
    volumes:
      - ./common/config/nginx:/etc/nginx:z
    networks:
      - harbor
    ports:
      - 80:80
      - 443:443
      - 4443:4443
    depends_on:
      - mysql
      - registry
      - ui
      - log
       logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://127.0.0.1:1514"
        tag: "proxy"
networks:
  harbor:
    external: false
    
[root@harbor harbor]# ./prepare  
[root@localhost harbor]# docker-compose up -d  //构建(容器)并启动(容器)整个project的所有service

4.访问Harbor查看存储容量
企业实战(6)修改Harbor镜像仓库默认存储路径
企业实战(6)修改Harbor镜像仓库默认存储路径
 访问harbor后可以看到镜像存储容量已经变成98G,就是我们定义的/mnt/harbordata的容量。

[root@harbor ~]# ls /mnt/harbordata/     //可以看到新建这个目录下已经有harbor生成的文件
ca_download  config  database  job_logs  psc  redis  registry  secretkey

注意:

 在整个部署过程中,不要手动修改上述关联挂载路径下的内容。若要修改相关内容,一定要保证在容器完全移除(docker-compose down)的前提下进行。

↓↓↓↓↓↓

最近刚申请了个微信公众号,上面也会分享一些运维知识,大家点点发财手关注一波,感谢大家。 【原创公众号】:非著名运维 【福利】:公众号回复 “资料” 送运维自学资料大礼包哦!
企业实战(6)修改Harbor镜像仓库默认存储路径

上一篇:基于 Harbor 搭建 Docker 私有镜像仓库


下一篇:Jenkins+Gitlab+Harbor+k8s 简易流水线