苏州营销型网站制作多少钱,自治区住房和城乡建设厅网站,项目式学习,网站开发毕业设计题目1. 介绍
Harbor 是一个开源的企业级 Docker 镜像仓库#xff0c;提供镜像存储、访问控制、安全扫描等功能。使用 Docker Compose 启动 Harbor 时#xff0c;您可以指定一个自定义网络#xff0c;以便管理容器之间的网络通信。在本示例中#xff0c;我们将创建一个名为 har…1. 介绍
Harbor 是一个开源的企业级 Docker 镜像仓库提供镜像存储、访问控制、安全扫描等功能。使用 Docker Compose 启动 Harbor 时您可以指定一个自定义网络以便管理容器之间的网络通信。在本示例中我们将创建一个名为 harbor 的网络并为其指定子网 172.18.0.0/16。
2. 创建 docker-compose.yml 文件
以下是一个包含 Harbor 服务和指定网络的 docker-compose.yml 配置文件
version: 3.7services:log:image: goharbor/harbor-log:v2.12.1container_name: harbor-logrestart: alwayscap_drop:- ALLcap_add:- CHOWN- DAC_OVERRIDE- SETGID- SETUIDvolumes:- /var/log/harbor/:/var/log/docker/:z- type: bindsource: ./common/config/log/logrotate.conftarget: /etc/logrotate.d/logrotate.conf- type: bindsource: ./common/config/log/rsyslog_docker.conftarget: /etc/rsyslog.d/rsyslog_docker.confports:- 127.0.0.1:1514:10514networks:- harborregistry:image: goharbor/registry-photon:v2.12.1container_name: registryrestart: alwayscap_drop:- ALLcap_add:- CHOWN- SETGID- SETUIDvolumes:- /data/registry:/storage:z- ./common/config/registry/:/etc/registry/:z- type: bindsource: /data/secret/registry/root.crttarget: /etc/registry/root.crt- type: bindsource: ./common/config/shared/trust-certificatestarget: /harbor_cust_certnetworks:- harbordepends_on:- loglogging:driver: syslogoptions:syslog-address: tcp://localhost:1514tag: registryregistryctl:image: goharbor/harbor-registryctl:v2.12.1container_name: registryctlenv_file:- ./common/config/registryctl/envrestart: alwayscap_drop:- ALLcap_add:- CHOWN- SETGID- SETUIDvolumes:- /data/registry:/storage:z- ./common/config/registry/:/etc/registry/:z- type: bindsource: ./common/config/registryctl/config.ymltarget: /etc/registryctl/config.yml- type: bindsource: ./common/config/shared/trust-certificatestarget: /harbor_cust_certnetworks:- harbordepends_on:- loglogging:driver: syslogoptions:syslog-address: tcp://localhost:1514tag: registryctlpostgresql:image: goharbor/harbor-db:v2.12.1container_name: harbor-dbrestart: alwayscap_drop:- ALLcap_add:- CHOWN- DAC_OVERRIDE- SETGID- SETUIDvolumes:- /data/database:/var/lib/postgresql/data:znetworks:- harborenv_file:- ./common/config/db/envdepends_on:- loglogging:driver: syslogoptions:syslog-address: tcp://localhost:1514tag: postgresqlshm_size: 1gbcore:image: goharbor/harbor-core:v2.12.1container_name: harbor-coreenv_file:- ./common/config/core/envrestart: alwayscap_drop:- ALLcap_add:- SETGID- SETUIDvolumes:- /data/ca_download/:/etc/core/ca/:z- /data/:/data/:z- ./common/config/core/certificates/:/etc/core/certificates/:z- type: bindsource: ./common/config/core/app.conftarget: /etc/core/app.conf- type: bindsource: /data/secret/core/private_key.pemtarget: /etc/core/private_key.pem- type: bindsource: /data/secret/keys/secretkeytarget: /etc/core/key- type: bindsource: ./common/config/shared/trust-certificatestarget: /harbor_cust_certnetworks:- harbordepends_on:- log- registry- redis- postgresqllogging:driver: syslogoptions:syslog-address: tcp://localhost:1514tag: coreportal:image: goharbor/harbor-portal:v2.12.1container_name: harbor-portalrestart: alwayscap_drop:- ALLcap_add:- CHOWN- SETGID- SETUID- NET_BIND_SERVICEvolumes:- type: bindsource: ./common/config/portal/nginx.conftarget: /etc/nginx/nginx.confnetworks:- harbordepends_on:- loglogging:driver: syslogoptions:syslog-address: tcp://localhost:1514tag: portaljobservice:image: goharbor/harbor-jobservice:v2.12.1container_name: harbor-jobserviceenv_file:- ./common/config/jobservice/envrestart: alwayscap_drop:- ALLcap_add:- CHOWN- SETGID- SETUIDvolumes:- /data/job_logs:/var/log/jobs:z- type: bindsource: ./common/config/jobservice/config.ymltarget: /etc/jobservice/config.yml- type: bindsource: ./common/config/shared/trust-certificatestarget: /harbor_cust_certnetworks:- harbordepends_on:- corelogging:driver: syslogoptions:syslog-address: tcp://localhost:1514tag: jobserviceredis:image: goharbor/redis-photon:v2.12.1container_name: redisrestart: alwayscap_drop:- ALLcap_add:- CHOWN- SETGID- SETUIDvolumes:- /data/redis:/var/lib/redisnetworks:- harbordepends_on:- loglogging:driver: syslogoptions:syslog-address: tcp://localhost:1514tag: redisproxy:image: goharbor/nginx-photon:v2.12.1container_name: nginxrestart: alwayscap_drop:- ALLcap_add:- CHOWN- SETGID- SETUID- NET_BIND_SERVICEvolumes:- ./common/config/nginx:/etc/nginx:z- type: bindsource: ./common/config/shared/trust-certificatestarget: /harbor_cust_certnetworks:- harborports:- 80:8080depends_on:- registry- core- portal- loglogging:driver: syslogoptions:syslog-address: tcp://localhost:1514tag: proxynetworks:harbor:external: falseipam:config:- subnet: 172.18.0.0/163. 关键配置说明 networks 部分: harbor: 定义了一个自定义的 Docker 网络。external: false: 表示该网络是 Docker Compose 创建的本地网络而不是外部已存在的网络。ipam: 配置了 IP 地址管理IPAM参数用来指定子网 172.18.0.0/16。 services 部分: 每个 Harbor 服务如 postgresql、core、registryctl 等都被配置为连接到 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 ps6. 停止 Harbor
如果需要停止 Harbor 服务可以使用以下命令
docker-compose down这样您就成功配置并启动了一个带有自定义网络的 Harbor Docker Compose 环境。如果您有其他问题或需要进一步调整配置随时可以提问