搭建极狐GitLab(基于Docker): 步骤整合汇总记录
执行背景:
(1) CentOS7(虚拟机ISO映像文件=CentOS-7-x86_64-DVD-2009.iso);
(2) repo(yum)源已切换为国内源;
命令汇总:
0. 准备
# 更新yum源
yum update
# 安装yum-utils工具、docker所需依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
# 设置镜像仓库
# 国外镜像
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 或者
# 阿里镜像
# https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
1. 安装Docker
相关命令:
# 查看仓库源中可使用版本
yum list docker-ce --showduplicates | sort -r
# 安装指定版本
yum install docker-ce-docker完整版本号
# 配置开机启动项
systemctl start docker
systemctl enable docker
# docker版本查看
#docker version
补充说明:
[root@localhost ~]# # 查看仓库源中可使用版本
[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror
可安装的软件包
* updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
* extras: mirrors.aliyun.com
docker-ce.x86_64 3:26.1.4-1.el7 docker-ce-stable
docker-ce.x86_64 3:26.1.3-1.el7 docker-ce-stable
...
* base: mirrors.aliyun.com
[root@localhost ~]# :<<'END'
> docker-ce.x86_64(=docker-ce.操作系统版本号)
> 3:26.1.4-1.el7(=3:docker版本号)
> => 下载docker的时候, 使用 docker-ce-docker版本号 指定所下载的版本, 比如 docker-ce-26.1.4-1.el7
> END
2. 环境变量设置 GITLAB_HOME
# 添加全局系统变量 GITLAB_HOME(在文件末尾添加 export GITLAB_HOME=/srv/gitlab 后保存)
# 按照官方文档 https://docs.gitlab.cn/jh/install/docker.html
# 对于Linux用户, 路径必须为 /srv/gitlab
vi ~/.bashrc

3. GitLab容器初始化
# 如果中途GitLab设置错误, 想重来
# 停止、删除现有容器
# docker stop gitlab
# docker rm gitlab
# 再 docker run
# 添加容器
#--hostname 192.168.44.103
docker run --detach \
--publish 443:443 \
--publish 80:80 \
--publish 222:22 \
--name gitlab \
--restart always \
--volume $GITLAB_HOME/config:/etc/gitlab:Z \
--volume $GITLAB_HOME/logs:/var/log/gitlab:Z \
--volume $GITLAB_HOME/data:/var/opt/gitlab:Z \
--shm-size 256m \
registry.gitlab.cn/omnibus/gitlab-jh:latest
# 或者使用简写形式
docker run -d \
-p 443:443 -p 80:80 -p 222:22 \
-name gitlab \
--restart always \
-v $GITLAB_HOME/config:/etc/gitlab:Z \
-v $GITLAB_HOME/logs:/var/log/gitlab:Z \
-v $GITLAB_HOME/data:/var/opt/gitlab:Z \
--shm-size 256m \
registry.gitlab.cn/omnibus/gitlab-jh:latest
# publish: 容器内端口映射到主机端口: 443、80、22分别对应https访问、http访问、ssh访问
# name: 指定容器名称
# restart always: 设置容器重启策略 为 始终重启
# volume: 设置容器与主机挂载对应:
# /etc/gitlab: 文件系统的安全上下文
# /var/log/gitlab: GitLab 的日志文件
# /var/opt/gitlab: GitLab 的数据
# 启动容器
docker start gitlab
# 简要查看docker容器内Gitlab运行情况
docker inspect gitlab --format "{{.State.Status}}"
# 查看已存在容器
# docker ps -a
# 进入GitLab容器内部
docker exec -it gitlab /bin/bash
4. 外网访问配置
主要是三处修改, 因为gitlab.rb全文件被注释, 所以可以选择 ①远处解开注释修改, 或者②直接随便找一个地方插进去
# 修改GitLab配置文件
vi /etc/gitlab/gitlab.rb
# 因为只是自己练习使用 直接使用虚拟机映射出去的IP来作为此处的GitLab访问IP
# 配置 http协议访问地址(端口不标识则默认视为80)
# external_url 'http://自定义访问ip:端口号'
external_url 'http://192.168.232.128'
# 配置ssh协议 访问地址和端口
# gitlab_rails['gitlab_shell_ssh_port'] = docekr run 命令配置gitlab时, ssh项映射端口号
gitlab_rails['gitlab_ssh_host'] = '192.168.232.128'
gitlab_rails['gitlab_shell_ssh_port'] = 222

5. 重启GitLab容器
# 重启GitLab
# 容器外部
docker restart gitlab
# 或者 容器内部
gitlab-ctl restart
6. 外网访问GitLab
文件external_url配置项对应内容

初次登录(管理员身份):
账号/密码 = root/容器中initial_root_password文件中读取(24h后会被注销, 密码需要自我存储/修改)

首次访问出现502: 原因:
- 虚拟机内存初始化设置 没有给予大于4G的内存, 导致GitLab无法成功启动
- 稍微等待, GitLab初始化还未完全
- 系统内核没有在3.10以上(使用命令进行核实:
uname -r
)
7. 一些设置
语言设置:

密码修改(GitLab平台上操作):

执行记录(部分):
[root@localhost ~]# # bashrc 文件已设置GITLAB_HOME系统变量完毕
[root@localhost ~]# cat ~/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export GITLAB_HOME=/srv/gitlab
[root@localhost ~]# docker run --detach \
> --publish 443:443 \
> --publish 80:80 \
> --publish 222:22\
> --name gitlab \
> --restart always \
> --volume $GITLAB_HOME/config:/etc/gitlab:Z \
> --volume $GITLAB_HOME/logs:/var/log/gitlab:Z \
> --volume $GITLAB_HOME/data:/var/opt/gitlab:Z \
> --shm-size 256m \
> registry.gitlab.cn/omnibus/gitlab-jh:latest
8428d380c939b0ac879b90621f35ceed0690e62995a4ae8e4872536709ee283b
[root@localhost ~]# docker start gitlab
gitlab
[root@localhost ~]# docker inspect gitlab --format "{{.State.Status}}"
running
[root@localhost ~]# # 进入容器内部, 修改GitLab配置文件, 方便外网访问
[root@localhost ~]# docker exec -it gitlab /bin/bash
root@8428d380c939:/# vi /etc/gitlab/gitlab.rb
root@8428d380c939:/# # 容器内部重启GitLab
root@8428d380c939:/# gitlab-ctl restart
ok: run: alertmanager: (pid 1387) 0s
ok: run: gitaly: (pid 1396) 0s
ok: run: gitlab-exporter: (pid 1409) 0s
ok: run: gitlab-kas: (pid 1420) 0s
ok: run: gitlab-workhorse: (pid 1428) 1s
ok: run: logrotate: (pid 1438) 0s
ok: run: nginx: (pid 1444) 1s
ok: run: postgres-exporter: (pid 1449) 0s
ok: run: postgresql: (pid 1456) 0s
ok: run: prometheus: (pid 1465) 1s
ok: run: puma: (pid 1473) 0s
ok: run: redis: (pid 1478) 1s
ok: run: redis-exporter: (pid 1486) 0s
ok: run: sidekiq: (pid 1493) 0s
ok: run: sshd: (pid 1499) 0s
root@8428d380c939:/# exit # 或 使用组合按键 ctrl+p+q
exit
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求