docker-compose.yml

version: '3.6'
services:
web:
image: 'gitlab/gitlab-ce:15.9.2-ce.0'
restart: always
hostname: 'project.example.com'
container_name: gitlab
environment:
TZ: Asia/Shanghai
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://project.example.com:1443'
gitlab_rails['gitlab_shell_ssh_port'] = 35022
# Add any other gitlab.rb configuration here, each on its own line
ports:
- '1443:1443'
- '35022:35022'
volumes:
- '/apps/gitlab/config:/etc/gitlab'
- '/apps/gitlab/logs:/var/log/gitlab'
- '/apps/gitlab/data:/var/opt/gitlab'
shm_size: '1g'

编辑gitlab.rb

# docker exec -it gitlab editor /etc/gitlab/gitlab.rb

修改默认端口

修改gitlab.rb

gitlab_rails['gitlab_shell_ssh_port'] = 35022
external_url 'http://project.example.com:1443'

运行gitlab

运行gitlab

# docker-compose up -d

查看运行状态

# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ae36d223590b gitlab/gitlab-ce:15.9.1-ce.0 "/assets/wrapper" 15 minutes ago Up 15 minutes (healthy) 22/tcp, 80/tcp, 0.0.0.0:1443->1443/tcp, 443/tcp, 0.0.0.0:35022->35022/tcp gitlab

启用SSL

修改gitlab.rb

# docker exec -it gitlab  egrep -v "^$|^#" /etc/gitlab/gitlab.rb
external_url 'https://project.example.com:1443'
nginx['enable'] = true
nginx['redirect_http_to_https'] = true
letsencrypt['enable'] = false

添加证书

# cp project.example.com.key project.example.com.crt /etc/gitlab/ssl/

SMTP 设置

修改gitlab.rb

gitlab_rails['smtp_pool'] = true
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxx@xx.com"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxx@xx.com'
gitlab_rails['smtp_domain'] = "exmail.qq.com"

测试SMTP

登录console

# docker exec -it gitlab gitlab-rails console
--------------------------------------------------------------------------------
Ruby: ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [x86_64-linux]
GitLab: 15.9.1 (de8f6619031) FOSS
GitLab Shell: 14.17.0
PostgreSQL: 13.8
------------------------------------------------------------[ booted in 46.23s ]
Loading production environment (Rails 6.1.7.2)
irb(main):001:0>

发送测试邮件 

irb(main):001:0> Notify.test_email('1304995320@qq.com', 'Message Subject', 'Message Body').deliver_now
Delivered mail 64006bf333e4_36c488054440@project.stars-mine.com.mail (2793.5ms)
=> #<Mail::Message:295800, Multipart: false, Headers: <Date: Thu, 02 Mar 2023 09:27:15 +0000>, <From: GitLab <contact@hard-chain.cn>>, <Reply-To: GitLab <noreply@project.stars-mine.com>>, <To: 1304995320@qq.com>, <Message-ID: <64006bf333e4_36c488054440@project.stars-mine.com.mail>>, <Subject: Message Subject>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
irb(main):002:0>

验证邮件

 

docker部署gitlab 15.9_nginx

重启gitlab

# docker-compose restart

重载配置文件

# docker exec -ti gitlab gitlab-ctl reconfigure

登录gitlab

查看gitlab密码

# docker exec -ti gitlab grep 'Password:' /etc/gitlab/initial_root_password
Password: /ulh38b2AlEBdWH/6XaDi38SLmkd82rw9HPLytU2PNo=

访问gitlab dashboard

URL: https://project.example.com:1443

docker部署gitlab 15.9_docker_02

docker部署gitlab 15.9_git_03

参考文档

​https://docs.gitlab.com/​