One-command DevOps platform: GitLab CE + SonarQube + Jenkins LTS + Nginx Gateway, managed via Docker Compose.
┌─────────────────────────────────────────────┐
│ Nginx Gateway (HTTPS) │
│ 80 → 301 redirect → 443 │
└──────┬──────────┬──────────┬────────────────┘
│ │ │
┌──────▼──┐ ┌─────▼───┐ ┌───▼──────────┐
│ GitLab │ │ Jenkins │ │ SonarQube │
│ CE │ │ LTS │ │ Community │
└─────────┘ └─────────┘ └───┬──────────┘
┌───▼──────────┐
│ PostgreSQL │
│ (backend_net)│
└──────────────┘
Network Isolation:
frontend_net— Gateway ↔ application services (GitLab, Jenkins, SonarQube)backend_net— SonarQube ↔ PostgreSQL only (database not exposed to gateway)
- Docker Desktop 已安装并 正在运行(菜单栏可见 Docker 图标)
- macOS / Linux 系统
- 可用内存 ≥ 8GB(推荐 16GB)
# 0. 确保 Docker Desktop 正在运行
docker info >/dev/null 2>&1 || open -a "Docker Desktop"
# 1. 初始化(自动生成密码、证书、.env 文件)
make init
# 2. 配置本地域名(需要 sudo 权限)
sudo sh -c 'echo "127.0.0.1 gitlab.devops.local jenkins.devops.local sonar.devops.local" >> /etc/hosts'
# 3. 启动所有服务
make up
# 4. 等待服务就绪(GitLab 首次启动约 3-5 分钟)
make ps
# 5. 获取初始密码
# GitLab:
docker exec gitlab grep 'Password:' /etc/gitlab/initial_root_password
# Jenkins:
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
# SonarQube: 默认 admin / admin(首次登录后修改)| 服务 | 地址 | 默认账号 |
|---|---|---|
| GitLab | https://gitlab.devops.local |
root / 见上方密码 |
| Jenkins | https://jenkins.devops.local |
admin / 见上方密码 |
| SonarQube | https://sonar.devops.local |
admin / admin |
⚠️ 浏览器会提示证书不受信任(自签名证书),点击「高级」→「继续访问」即可。
如果之前运行过旧版配置,可能会遇到容器名称冲突,执行:
docker compose down --remove-orphans
make up如果 SonarQube 报 Elasticsearch 错误(Lucene912 codec not found),清理旧数据:
rm -rf sonarqube/data/es8/*
docker compose restart sonarqube| Service | Image | Access | Purpose |
|---|---|---|---|
| Gateway | nginx:1.27.5-alpine |
https://*.devops.local |
HTTPS reverse proxy |
| GitLab | gitlab-ce:17.11.2 |
https://gitlab.devops.local |
Source code management |
| Jenkins | jenkins:2.504.3-lts |
https://jenkins.devops.local |
CI/CD pipeline |
| SonarQube | sonarqube:10.6.0 |
https://sonar.devops.local |
Code quality analysis |
| PostgreSQL | postgres:15.8-alpine |
Internal only | SonarQube database |
Additional ports:
- GitLab SSH:
localhost:2222 - Jenkins Agent:
localhost:50000
make help # Show all available targets
make init # First-time setup (secrets + certs + .env)
make up # Start all services
make down # Stop all services
make ps # Show service status
make logs SERVICE=git # Tail logs (omit SERVICE for all)
make restart SERVICE=gitlab
make validate # Validate compose + nginx configs
make backup # Backup all data to backups/
make scan # Scan images for CVEs (requires trivy)
make monitoring-up # Start Prometheus + Grafana
make monitoring-down # Stop monitoring stack
make clean # Remove all data (DESTRUCTIVE).
├── .env.example # Environment variable template
├── .env # Active env config (gitignored)
├── docker-compose.yml # Main service definitions
├── docker-compose.monitoring.yml # Monitoring overlay (optional)
├── Makefile # Automation commands
├── gateway/
│ ├── nginx.conf # HTTPS reverse proxy config
│ ├── certs/ # TLS certificates (gitignored)
│ └── snippets/
│ ├── security-headers.conf # Shared security headers
│ └── proxy-params.conf # Shared proxy parameters
├── monitoring/
│ └── prometheus.yml # Prometheus scrape config
├── scripts/
│ ├── backup.sh # Data backup script
│ ├── scan-images.sh # Vulnerability scanner
│ └── validate.sh # Configuration validator
├── secrets/ # Docker secrets (gitignored)
├── gitlab/ # GitLab runtime data
├── jenkins_home/ # Jenkins runtime data
├── postgresql/ # PostgreSQL runtime data
├── sonarqube/ # SonarQube runtime data
└── backups/ # Backup archives
Copy .env.example to .env and customize. Key variables:
| Variable | Default | Description |
|---|---|---|
GITLAB_IMAGE |
gitlab/gitlab-ce:17.11.2-ce.0 |
GitLab image tag |
JENKINS_IMAGE |
jenkins/jenkins:2.504.3-lts-jdk21 |
Jenkins image tag |
SONARQUBE_IMAGE |
sonarqube:10.6.0-community |
SonarQube image tag |
POSTGRES_IMAGE |
postgres:15.8-alpine3.20 |
PostgreSQL image tag |
GITLAB_MEMORY |
4g |
GitLab memory limit |
JENKINS_MEMORY |
2g |
Jenkins memory limit |
SONARQUBE_MEMORY |
2g |
SonarQube memory limit |
Database passwords use Docker secrets:
# Auto-generated during `make init` (random 24-byte password)
# Or set manually:
echo "your-strong-password" > secrets/sonar_db_password.txt
chmod 600 secrets/sonar_db_password.txtSelf-signed certificates are auto-generated during make init. For trusted certs:
# Using mkcert (recommended for local development)
brew install mkcert
mkcert -install
mkcert -key-file gateway/certs/devops.local.key \
-cert-file gateway/certs/devops.local.crt \
"*.devops.local"Start the monitoring stack:
make monitoring-up| Service | URL | Credentials |
|---|---|---|
| Prometheus | http://localhost:9090 |
— |
| Grafana | http://localhost:3000 |
admin / changeme |
# Backup all services
make backup
# Backup a specific service
make backup SERVICE=gitlab
# Restore PostgreSQL
gunzip -c backups/<timestamp>/sonarqube_db.sql.gz | \
docker exec -i sonarqube-db psql -U sonar sonar
# Restore Jenkins
tar xzf backups/<timestamp>/jenkins_home.tar.gzRetention: keeps last 7 backups (configurable via RETENTION_COUNT env var).
make validateChecks:
- Tool prerequisites (docker, openssl)
- Configuration file existence
- Docker Compose syntax
- Nginx syntax
- Secrets & certificates
/etc/hostsentries- File permissions & security
- ✅ Fixed image tags (no
latestdrift) - ✅ Docker secrets for database passwords (not in Compose file)
- ✅ Nginx:
cap_drop: ALL+ read-only filesystem +no-new-privileges - ✅ Network isolation (database on separate network)
- ✅ TLS 1.2+ only with modern cipher suites
- ✅ Security response headers (HSTS, X-Frame-Options, CSP)
- ✅ Rate limiting (10 req/s per IP with burst)
- ✅ Container resource limits (memory + CPU)
- ✅ Log rotation (json-file driver with size limits)
- ✅ Health checks for all services
- ✅ Gateway: no shell, minimal capabilities
⚠️ Jenkins runs as root with Docker socket mounted — required for Docker-in-Docker builds. For production, consider:- Docker-in-Docker (dind) sidecar with TLS
- Remote Docker daemon with certificate auth
- Kaniko / Buildah for rootless builds
⚠️ Self-signed certificates — browser will show warnings. Usemkcertfor trusted local certs.
| Symptom | Cause | Fix |
|---|---|---|
connect: no such file or directory |
Docker Desktop 未运行 | 先启动 Docker Desktop: open -a "Docker Desktop" |
| Container name conflict | 旧容器未清理 | docker compose down --remove-orphans |
| Gateway 不断重启 | 后端服务 DNS 不可达 | 等待所有服务启动: make ps,确认 sonarqube/jenkins/gitlab 正常 |
| 502 Bad Gateway | Backend 仍在初始化 | 等待 2-3 min,检查 make logs SERVICE=<name> |
| GitLab 首次启动慢 | 正常现象 | 等待最多 5 分钟 |
SonarQube Lucene912 codec not found |
旧版 ES 数据不兼容 | rm -rf sonarqube/data/es8/* && docker compose restart sonarqube |
GitLab platform does not match |
amd64 镜像在 ARM 上运行 | 正常,通过 Rosetta 模拟,会稍慢 |
| SonarQube 无法启动 | DB 尚未 healthy | docker inspect --format='{{json .State.Health}}' sonarqube-db |
| 浏览器证书警告 | 自签名证书 | 使用 mkcert 或点击「继续访问」 |
| Jenkins docker.sock 权限问题 | socket group 不匹配 | 确保 /var/run/docker.sock 对 Jenkins 用户可访问 |