官方文档: 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: '[email protected]')
-
-
重置密码
-
设置随机密码
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