# DockerCompose运行配置Gitlab
# 部署规范
所有的基础服务,例如:MySQL、Redis、Nginx、Gitlab、Jenkins、Harbor等一律用DockerCompose部署。有且仅有应用,可以部署到k8s集群。
# 开始部署
# docker-compose-gitlab.yaml
version: '3'
services:
gitlab:
# image: gitlab/gitlab-ce:14.8.2-ce.0
image: gitlab/gitlab-ce:16.11.3-ce.0
container_name: gitlab-ce-16113
# on-failure 是指在容器退出时,当其退出状态码不为0(即失败)时,自动重启该容器。具体来说,它会重启那些在容器退出时返回非0状态码的容器。如果容器在退出时返回状态码0,则不会自动重启该容器。
# no:容器退出时不重启容器;
# always:容器退出时总是重启容器;
# unless-stopped:容器退出时重启容器,除非容器被手动停止。
restart: unless-stopped
volumes:
- "./gitlab/etc:/etc/gitlab"
- "./gitlab/log:/var/log/gitlab"
- "./gitlab/opt:/var/opt/gitlab"
environment:
TZ: Asia/Shanghai
LANG: en_US.UTF-8
privileged: true
user: root
# 本机端口:容器内端口
ports:
- "2443:443"
- "2080:80"
- "2022:22"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 如果没有docker-compose就安装一个
sudo curl -L "https://oss.odboy.cn/blog/files/docker-compose-linux-x86_64-v2.27.1" -o /usr/local/bin/docker-compose
sudo chmod a+x /usr/local/bin/docker-compose
1
2
2
# 执行脚本
docker-compose -f docker-compose-gitlab.yaml -p gitlab16 up -d
1
# 配置gitlab
# 备份
cp ./gitlab/etc/gitlab.rb ./gitlab/etc/gitlab.rb.bak20240528
# 覆盖原配置
cat << EOF > ./gitlab/etc/gitlab.rb
# gitlab访问地址,填写域名或IP地址,如果端口不写的话默认为80端口
# 192.168.235.100 这个地址是我本地虚机的IP
external_url 'http://192.168.235.100:2080'
# 如果你只是这样改,你会发现gitlab访问不了。
# 因为Gitlab默认会用这个端口号作为其Nginx的监听端口。因为我们这里其实是监听的80端口,所以需要加如下配置:
nginx['listen_port'] = 80
# 当然,这个配置也别忘记了
gitlab_rails['gitlab_shell_ssh_port'] = 22
# 下面是用个人QQ邮箱发邮件的配置
#gitlab_rails['smtp_enable'] = true
#gitlab_rails['smtp_address'] = "smtp.qq.com"
#gitlab_rails['smtp_port'] = 465
#gitlab_rails['smtp_user_name'] = "1943815081@qq.com"
#gitlab_rails['smtp_password'] = "授权码"
#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'] = '1943815081@qq.com'
EOF
# 重新配置gitlab
docker exec -it $(docker ps|grep gitlab-ce:16.11|awk '{print $1}') gitlab-ctl reconfigure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 自定义ssh地址
vi ./gitlab/opt/gitlab-rails/etc/gitlab.yml
1
# 查看gitlab管理员root密码
#cat ./gitlab/etc/initial_root_password|grep Password|grep -v '#'
docker exec -it 容器id cat /etc/gitlab/initial_root_password|grep Password|grep -v '#'
1
2
2