CentOS 上 GitLab 与 Docker 集成方案
一 架构与前置条件
二 安装 Docker 与 Docker Compose
三 部署 GitLab 与内置 Container Registry
version: '3.8'
services:
gitlab:
image: gitlab/gitlab-ce:latest
container_name: gitlab
restart: unless-stopped
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://gitlab.example.com'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
registry_external_url 'https://registry.example.com:5000'
registry['enable'] = true
# 如需自签名或已有证书,取消下一行注释并配置证书路径
# registry_nginx['ssl_certificate'] = "/etc/gitlab/ssl/registry.crt"
# registry_nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/registry.key"
ports:
- '80:80'
- '443:443'
- '2222:22'
- '5000:5000'
volumes:
- /data/gitlab/config:/etc/gitlab
- /data/gitlab/logs:/var/log/gitlab
- /data/gitlab/data:/var/opt/gitlab
四 使用 GitLab Runner 构建并推送镜像
stages:
- build
build_push:
stage: build
image: docker:latest
services:
- docker:dind
variables:
IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
before_script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
script:
- docker build -t $IMAGE .
- docker push $IMAGE
only:
- main
五 安全加固与运维要点