参考官方安装方法:Install GitLab using Docker Compose
vim docker-compose.yml
version: '3.6'
services:
web:
image: 'gitlab/gitlab-ce:latest' # 默认最新镜像,亦可指定版本
container_name: gitlab
restart: unless-stopped
privileged: true
hostname: 'gitlab.l2c.com'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.l2c.com' #项目clone地址,需与hostname一致,默认80端口
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
ports:
- '80:80' #默认80 自定义主机端口时需同步修改external_url
- '443:443'
- '2222:22'
volumes:
- '/data/gitlab/config:/etc/gitlab'
- '/data/gitlab/data:/var/opt/gitlab'
- '/data/gitlab/logs:/var/log/gitlab'
# 部署
docker-compose up -d
# 查看状态
docker ps -a |grep gitlab
# 停止
docker-compose down
docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
version: '3.6'
services:
web:
image: 'gitlab/gitlab-ce:latest' # 默认最新镜像,亦可指定版本
container_name: gitlab
restart: unless-stopped
privileged: true
hostname: 'gitlab'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://192.168.17.200' #项 本机IP地址
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
ports:
- '80:80' #默认80 自定义主机端口时需不同修改external_url
- '443:443'
- '2222:22'
volumes:
- '/data/gitlab/config:/etc/gitlab'
- '/data/gitlab/data:/var/opt/gitlab'
- '/data/gitlab/logs:/var/log/gitlab'
version: '3.6'
services:
web:
image: 'gitlab/gitlab-ce:latest' # 默认最新镜像,亦可指定版本
container_name: gitlab
restart: unless-stopped
privileged: true
hostname: 'gitlab.l2c.com'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.l2c.com:8888' #项目clone地址,需与hostname一致,默认80端口
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
ports:
- '8888:8888' #自定义端口
- '443:443'
- '2222:22'
volumes:
- '/data/gitlab/config:/etc/gitlab'
- '/data/gitlab/data:/var/opt/gitlab'
- '/data/gitlab/logs:/var/log/gitlab'
启用邮箱后需手动修改管理员默认邮箱
version: '3.6'
services:
web:
image: 'gitlab/gitlab-ce:latest' # 默认最新镜像,亦可指定版本
container_name: gitlab
restart: unless-stopped
privileged: true
hostname: 'gitlab.l2c.com'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.l2c.com' #项目clone地址,需与hostname一致,默认80端口
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxxxxxx@qq.com" # 用自己的邮箱
gitlab_rails['smtp_password'] = "xxxxxxxx" # 开启smtp后生成的授权码
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxxxxxx@qq.com'
alertmanager['admin_email'] = 'admin@example.com' # 设置管理员邮箱
ports:
- '80:80' #默认80 自定义主机端口时需不同修改external_url
- '443:443'
- '2222:22'
volumes:
- '/data/gitlab/config:/etc/gitlab'
- '/data/gitlab/data:/var/opt/gitlab'
- '/data/gitlab/logs:/var/log/gitlab'
logging:
driver: "json-file"
options:
max-size: "200m"
max-file: "10"
docker-compose up -d
vim /data/gitlab/config/gitlab.rb
# 编辑邮箱配置
# 进入gitlab容器
docker exec -it gitlab /bin/bash
# 重载配置
gitlab-ctl reconfigure
# 进入控制台(需要一点时间)
gitlab-rails console
# 发送测试邮件
Notify.test_email('xxxxxxxx@qq.com','gitlab邮箱测试','gitlab邮箱测试').deliver_now
mkdir -p ./ssl
cd ./ssl
openssl req -newkey rsa:4096 -nodes -sha256 -keyout ca.key -x509 -days 3650 -out ca.crt
# 一路回车出现Common Name 输入(因为是CA,可不输入IP或域名):L2C Cert Root CA
# L2C为自定义名称
openssl req -newkey rsa:4096 -nodes -sha256 -keyout gitlab.key -out gitlab.csr
# 一路回车出现Common Name 输入IP或域名:l2c.com
vim extfile.cnf
subjectAltName = @alt_names
extendedKeyUsage = serverAuth
[alt_names]
# 域名,如有多个用DNS.2,DNS.3…来增加
DNS.1 = l2c.com
DNS.2 = *.l2c.com
# IP地址, 服务器的ip
IP.1 = 192.168.17.200
IP.2 = 127.0.0.1
openssl x509 -req -days 3650 -in gitlab.csr -CA ca.crt -CAkey ca.key -CAcreateserial -extfile extfile.cnf -out gitlab.crt
scp ca.crt root@[IP]:/etc/pki/ca-trust/source/anchors/
update-ca-trust extract
mkdir -p /data/gitlab/config/trusted-certs
cp gitlab.crt gitlab.key /data/gitlab/config/trusted-certs
version: '3.6'
services:
web:
image: 'gitlab/gitlab-ce:latest' # 默认最新镜像,亦可指定版本
container_name: gitlab
restart: unless-stopped
privileged: true
hostname: 'gitlab.l2c.com'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://gitlab.l2c.com' #项目clone地址,需与hostname一致,默认80端口
nginx['redirect_http_to_https']= true #取消注释改为 true
nginx['ssl_certificate'] = "/etc/gitlab/trusted-certs/gitlab.crt" #放置对应的证书密钥
nginx['ssl_certificate_key'] = "/etc/gitlab/trusted-certs/gitlab.key" #放置对应的证书密钥
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxxxxxx@qq.com" # 用自己的邮箱
gitlab_rails['smtp_password'] = "xxxxxxxx" # 开启smtp后生成的授权码
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxxxxxx@qq.com'
ports:
- '80:80' #默认80 自定义主机端口时需不同修改external_url
- '443:443'
- '2222:22'
volumes:
- '/data/gitlab/config:/etc/gitlab'
- '/data/gitlab/data:/var/opt/gitlab'
- '/data/gitlab/logs:/var/log/gitlab'
logging:
driver: "json-file"
options:
max-size: "200m"
max-file: "10"
# 查看配置
git config --list
git config --global user.name "xxx"
git config --global user.email xxxxxxxx@xxx.com
# 启用store模式,输入密码后,会以明文形式默认保存于~/.git-credentials
git config --global credential.helper store