当前位置: 首页 > article >正文

Docker Compose 启动 Harbor 并指定网络

1. 介绍

Harbor 是一个开源的企业级 Docker 镜像仓库,提供镜像存储、访问控制、安全扫描等功能。使用 Docker Compose 启动 Harbor 时,您可以指定一个自定义网络,以便管理容器之间的网络通信。在本示例中,我们将创建一个名为 harbor 的网络,并为其指定子网 172.18.0.0/16

2. 创建 docker-compose.yml 文件

以下是一个包含 Harbor 服务和指定网络的 docker-compose.yml 配置文件:

version: '3.7'

services:
  log:
    image: goharbor/harbor-log:v2.12.1
    container_name: harbor-log
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - DAC_OVERRIDE
      - SETGID
      - SETUID
    volumes:
      - /var/log/harbor/:/var/log/docker/:z
      - type: bind
        source: ./common/config/log/logrotate.conf
        target: /etc/logrotate.d/logrotate.conf
      - type: bind
        source: ./common/config/log/rsyslog_docker.conf
        target: /etc/rsyslog.d/rsyslog_docker.conf
    ports:
      - 127.0.0.1:1514:10514
    networks:
      - harbor

  registry:
    image: goharbor/registry-photon:v2.12.1
    container_name: registry
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
    volumes:
      - /data/registry:/storage:z
      - ./common/config/registry/:/etc/registry/:z
      - type: bind
        source: /data/secret/registry/root.crt
        target: /etc/registry/root.crt
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
    networks:
      - harbor
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "registry"

  registryctl:
    image: goharbor/harbor-registryctl:v2.12.1
    container_name: registryctl
    env_file:
      - ./common/config/registryctl/env
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
    volumes:
      - /data/registry:/storage:z
      - ./common/config/registry/:/etc/registry/:z
      - type: bind
        source: ./common/config/registryctl/config.yml
        target: /etc/registryctl/config.yml
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
    networks:
      - harbor
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "registryctl"

  postgresql:
    image: goharbor/harbor-db:v2.12.1
    container_name: harbor-db
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - DAC_OVERRIDE
      - SETGID
      - SETUID
    volumes:
      - /data/database:/var/lib/postgresql/data:z
    networks:
      - harbor
    env_file:
      - ./common/config/db/env
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "postgresql"
    shm_size: '1gb'

  core:
    image: goharbor/harbor-core:v2.12.1
    container_name: harbor-core
    env_file:
      - ./common/config/core/env
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - SETGID
      - SETUID
    volumes:
      - /data/ca_download/:/etc/core/ca/:z
      - /data/:/data/:z
      - ./common/config/core/certificates/:/etc/core/certificates/:z
      - type: bind
        source: ./common/config/core/app.conf
        target: /etc/core/app.conf
      - type: bind
        source: /data/secret/core/private_key.pem
        target: /etc/core/private_key.pem
      - type: bind
        source: /data/secret/keys/secretkey
        target: /etc/core/key
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
    networks:
      - harbor
    depends_on:
      - log
      - registry
      - redis
      - postgresql
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "core"

  portal:
    image: goharbor/harbor-portal:v2.12.1
    container_name: harbor-portal
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
      - NET_BIND_SERVICE
    volumes:
      - type: bind
        source: ./common/config/portal/nginx.conf
        target: /etc/nginx/nginx.conf
    networks:
      - harbor
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "portal"

  jobservice:
    image: goharbor/harbor-jobservice:v2.12.1
    container_name: harbor-jobservice
    env_file:
      - ./common/config/jobservice/env
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
    volumes:
      - /data/job_logs:/var/log/jobs:z
      - type: bind
        source: ./common/config/jobservice/config.yml
        target: /etc/jobservice/config.yml
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
    networks:
      - harbor
    depends_on:
      - core
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "jobservice"

  redis:
    image: goharbor/redis-photon:v2.12.1
    container_name: redis
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
    volumes:
      - /data/redis:/var/lib/redis
    networks:
      - harbor
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "redis"

  proxy:
    image: goharbor/nginx-photon:v2.12.1
    container_name: nginx
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
      - NET_BIND_SERVICE
    volumes:
      - ./common/config/nginx:/etc/nginx:z
      - type: bind
        source: ./common/config/shared/trust-certificates
        target: /harbor_cust_cert
    networks:
      - harbor
    ports:
      - 80:8080
    depends_on:
      - registry
      - core
      - portal
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "proxy"

networks:
  harbor:
    external: false
    ipam:
      config:
         - subnet: 172.18.0.0/16
3. 关键配置说明
  • networks 部分:

    • harbor: 定义了一个自定义的 Docker 网络。
    • external: false: 表示该网络是 Docker Compose 创建的本地网络,而不是外部已存在的网络。
    • ipam: 配置了 IP 地址管理(IPAM)参数,用来指定子网 172.18.0.0/16
  • services 部分:

    • 每个 Harbor 服务(如 postgresqlcoreregistryctl 等)都被配置为连接到 harbor 网络。
    • depends_on 关键字用来指定容器之间的启动顺序,例如,core 服务需要在 postgresql 启动后启动。
  • ports 部分:

    • proxy 服务通过 ports 关键字将容器的端口映射到主机

端口,以便外部可以访问 Harbor 服务。

4. 启动 Harbor

在包含 docker-compose.yml 文件的目录中,使用以下命令启动 Harbor:

docker-compose up -d

这将启动所有 Harbor 服务并连接到您定义的自定义网络 harbor

5. 查看容器状态

您可以使用以下命令检查 Harbor 服务容器的运行状态:

docker-compose ps
6. 停止 Harbor

如果需要停止 Harbor 服务,可以使用以下命令:

docker-compose down

这样,您就成功配置并启动了一个带有自定义网络的 Harbor Docker Compose 环境。如果您有其他问题或需要进一步调整配置,随时可以提问!


http://www.kler.cn/a/471052.html

相关文章:

  • flutter 专题二十四 Flutter性能优化在携程酒店的实践
  • 【HarmonyOS NEXT】鸿蒙应用使用后台任务之长时任务,解决屏幕录制音乐播放等操作不被挂起
  • [笔记] Jenkins 安装与配置全攻略:Ubuntu 从零开始搭建持续集成环境
  • 【机器学习:四、多输入变量的回归问题】
  • STM32-笔记35-DMA(直接存储器访问)
  • 关于FPGA中添加FIR IP核(采用了GOWIN EDA)
  • Power BI如何连接Azure Databricks数据源?
  • 什么是Lua协同程序?和线程有什么区别?
  • vue.js sync修饰符
  • STM32拓展 低功耗案例1:睡眠模式 (hal)
  • 【学习笔记】数据结构(十)
  • NLP三大特征抽取器(CNN/RNN/TF)
  • 【Uniapp-Vue3】navigator路由与页面跳转
  • Elasticsearch与数据库数据一致性:最佳实践与解决方案
  • 基于大数据爬虫+Python+数据可视化大屏的慧游数据爬虫与推荐分析系统(源码+论文+PPT+部署文档教程等)
  • Linux 安装 meilisearch
  • NUTTX移植到STM32
  • c#使用SevenZipSharp实现压缩文件和目录
  • Appium(一)--- 环境搭建
  • 【简博士统计学习方法】1. 统计学习的定义与分类
  • Functions
  • CANN 学习——基于香橙派 KunpengPro(1)
  • 03-其他
  • Java面试要点114 - Java ThreadLocal原理与内存泄漏
  • 《机器学习》——随机森林
  • 对话|企业如何构建更完善的容器供应链安全防护体系