ubuntu24.04使用docker搭建gitlab

先按照 这里配置docker

然后使用 docker compose 配置,更新简单

创建docker-compose文件

创建 docker-compose.yaml 文件,内容如下

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
services:

gitlab:
# https://hub.docker.com/r/gitlab/gitlab-ce/tags
image: docker.io/gitlab/gitlab-ce:16.11.1-ce.0
container_name: gitlab
restart: always
networks:
- icpcs
environment:
- GITLAB_RELATIVE_URL_ROOT=/gitlab
ports:
- 208:80
- 230:22
volumes:
- /data/docker_apps/gitlab-ce/config:/etc/gitlab
- /data/docker_apps/gitlab-ce/logs:/var/log/gitlab
- /data/docker_apps/gitlab-ce/data:/var/opt/gitlab


networks:
icpcs:
driver: bridge
ipam:
config:
- subnet: 10.13.0.0/16
gateway: 10.13.0.1

  • 注意,10.13.0 不要与本地网络其他ip冲突
  • 版本为 gitlab-ce:16.11.1-ce.0 可以在 docker-hub 查看有哪些版本

创建本地数据目录

这里数据都放在了 /data/docker_apps/gitlab-ce 这里,你也可以放在其他地方,但是注意上面docker-compose文件中对应的路径也要修改

1
2
3
mkdir /data/docker_apps/gitlab-ce/config
mkdir /data/docker_apps/gitlab-ce/logs
mkdir /data/docker_apps/gitlab-ce/data

安装

docker-compose.yaml 文件所在目录,执行

注意最新版没有 docker-compose

1
docker compose up -d

配置

只能作参考,比如 xxx@163.com 改成你的邮箱,mailpasswd 改成你的密码

1
vim /data/docker_apps/gitlab-ce/config/gitlab.rb
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
external_url 'https://xxxx.cn/gitlab'

gitlab_rails['gitlab_ssh_host'] = 'xxxx.cn'
gitlab_rails['gitlab_shell_ssh_port'] = 230


gitlab_rails['backup_keep_time'] = 7776000

sidekiq['concurrency'] = 32
postgresql['shared_buffers'] = "1024MB"
postgresql['max_worker_processes'] = 16

puma['per_worker_max_memory_mb'] = 51200
puma['worker_processes'] = 25


gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxx@163.com"
gitlab_rails['smtp_password'] = "mailpasswd"
gitlab_rails['smtp_domain'] = "smtp.163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_pool'] = false
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'xxx@163.com'
gitlab_rails['gitlab_email_reply_to'] = 'xxx@163.com'

nginx 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server {
listen 82;
server_name xxxx.cn;

absolute_redirect off;
#上传会被限制
client_max_body_size 1024m;


location /gitlab/ {
#add_header Set-Cookie "__Host-Prefix=true; Path=/nc; Secure; SameSite=Strict";
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains; preload;" always;
add_header X-Download-Options noopen;
proxy_set_header Host $host;

proxy_pass http://localhost:208/gitlab/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

更新

直接再次在 docker-compose.yaml 文件所在目录运行这个命令即可

1
docker compose up -d

本文作者:yuhldr
本文地址: https://yuhldr.github.io/posts/62cb640b.html
版权声明:转载请注明出处!