您现在的位置是:首页 > 博文答疑 > Gitlab 本地环境搭建博文答疑

Gitlab 本地环境搭建

Leo2025-10-22【6】

简介让你拥有自己的git服务器

 

Gitlab 本地环境搭建

拉取镜像,启动容器

docker pull gitlab/gitlab-ce

localhost:/docker# docker images
REPOSITORY         TAG       IMAGE ID       CREATED        SIZE
gitlab/gitlab-ce   latest    fef3e02c1cc7   6 hours ago    3.88GB
hello-world        latest    74cc54e27dc4   9 months ago   10.1kB

mkdir -p /docker/gitlab/config
mkdir -p /docker/gitlab/logs
mkdir –p /docker/gitlab/data 


docker run -d  \
  -p 443:443 \
  -p 8081:80 \
  -p 222:22 \
  --name gitlab \
  --restart always \
  -v /docker/gitlab/config:/etc/gitlab \
  -v /docker/gitlab/logs:/var/log/gitlab \
  -v /docker/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce


# 启动时间有点久, 硬件上,内存最好4G以上,人少的话建议6G.

访问和测试

http://192.168.222.10:8081

初始账户: root

查看初始密码

docker exec -it gitlab bash
cat /etc/gitlab/initial_root_password


localhost:~# docker exec -it gitlab bash
root@b2648929964d:/# cat /etc/gitlab/initial_root_password
# WARNING: This password is only valid if ALL of the following are true:
#          • You set it manually via the GITLAB_ROOT_PASSWORD environment variable
#            OR the gitlab_rails['initial_root_password'] setting in /etc/gitlab/gitlab.rb
#          • You set it BEFORE the initial database setup (typically during first installation)
#          • You have NOT changed the password since then (via web UI or command line)
#
#          If this password doesn't work, reset the admin password using:
#          https://docs.gitlab.com/security/reset_user_password/#reset-the-root-password

Password: oNEGt5KRN77HN6AWQHJ8dPZigIFq6bE0jcPXg0WYFWQ=

不喜欢英文界面的小伙伴们。

  • • 登录后,点击右上角的用户头像 → Preferences(偏好设置)
  • • 在左侧菜单中找到 Language(语言) 选项,下拉选择 简体中文 或 繁體中文
  • • 点击页面底部的 Save changes(保存更改),界面会立即切换为中文。

GitLab 系统邮箱设置:

找到配置文件,就在我们之前创建的config文件夹里:/docker/gitlab/config/gitlab.rb

下面是通用的模板。163 或者 qq 邮箱配置 可以自己搜索。

# 配置发件人邮箱(需与 SMTP 认证的邮箱一致)
gitlab_rails['gitlab_email_from'] = 'your-email@example.com'
gitlab_rails['gitlab_email_reply_to'] = 'your-email@example.com'  # 回复地址

# SMTP 服务器配置
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.example.com"  # SMTP 服务器地址(如 smtp.qq.com、smtp.163.com)
gitlab_rails['smtp_port'] = 587  # SMTP 端口(常用 587 带 STARTTLS,465 带 SSL)
gitlab_rails['smtp_user_name'] = "your-email@example.com"  # 邮箱账号
gitlab_rails['smtp_password'] = "your-password-or-auth-code"  # 邮箱密码(或授权码,如 QQ 邮箱需用授权码)
gitlab_rails['smtp_domain'] = "example.com"  # 邮箱域名(如 qq.com、163.com)
gitlab_rails['smtp_authentication'] = "login"  # 认证方式(通常为 login,部分服务

修改之后, 在宿主机 保存重启

docker exec -it gitlab gitlab-ctl reconfigure

docker restart gitlab

测试:

# 进入控制台
docker exec -it gitlab gitlab-rails console
# 发测试邮件
Notify.test_email('test@example.com', '测试邮件标题', '测试邮件内容').deliver_now

# 如果没有收到邮件,宿主机中查询log 排查:
docker exec -it gitlab gitlab-ctl tail sidekiq