Gitlab Docker 使用摘要
官方文档: https://docs.gitlab.com/ee/install/docker.html#expose-gitlab-on-different-ports
设置本地目录
- 设置环境变量 GITLAB_HOME
export GITLAB_HOME=/srv/gitlab
安装
- 启动脚本
start.sh
#!/bin/bash export GITLAB_HOME=/srv/gitlab sudo docker run --detach \ --privileged \ --hostname gitlab.example.com \ --publish 8980:8980 --publish 8922:22 \ --name gitlab \ --network bridge \ --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 \ gitlab/gitlab-ee:latest
配置
配置文件位置: /etc/gitlab/gitlab.rb
务必保证
/etc/gitlab/gitlab.rb
配置文件中的external_url
是真实有效的可访问的地址
重启使配置生效
sudo docker restart gitlab
使用非默认端口
Gitlab 默认使用 80, 443, 22 等端口, 若不使用默认端口,则需修改配置文件 /etc/gitlab/gitlab.rb
若设置Web 端口
# For HTTP external_url "http://gitlab.example.com:8929" # or # For HTTPS (notice the https) # external_url "https://gitlab.example.com:8929"
若设置ssh端口
gitlab_rails['gitlab_shell_ssh_port'] = 2289
重新配置gitlab
gitlab-ctl reconfigure
重置root密码
首先需要登录gitlab容器内部,如果gitlab容器的名称为 gitlab, 进入容器
docker exec -it gitlab bash
Use a Rake task
gitlab-rake "gitlab:password:reset"
Use a Rails console
-
打开rails控制台
gitlab-rails console -
查找用户
-
By username
user = User.find_by_username 'root'
-
By user ID(root 用户id为1)
user = User.find(1)
-
By email address
user = User.find_by(email: 'root@example.com')
-
-
重置密码
-
设置随机密码
new_password = ::User.random_password user.password = new_password user.password_confirmation = new_password user.password_automatically_set = false -
设置指定密码
new_password = 'examplepassword' user.password = new_password user.password_confirmation = new_password user.password_automatically_set = false
-
-
保存
user.save! -
退出
exit
Troubleshooting
- Email confirmation issues
If the new password doesn’t work, it might be an email confirmation issue. You can attempt to fix this issue in a Rails console. For example, if a new root password isn’t working:
- Start a Rails console.
- Find the user and skip reconfirmation:
user = User.find(1) user.skip_reconfirmation!
- Attempt to sign in again
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)