docker安装gitlab

moonjerx
2021-10-12 / 0 评论 / 152 阅读 / 正在检测是否收录...

一、直接运行docker命令

docker run -d --name gitlab \
  --restart always \
  -p 30001:30001 \
  -p 30002:30002 \
  -p 30003:22 \
  -v /home/$USER/dockerfile/gitlab/etc:/etc/gitlab \
  -v /home/$USER/dockerfile/gitlab/logs:/var/log/gitlab \
  -v /home/$USER/dockerfile/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest

额外参数:

--hostname 192.168.1.8 \
  • 官方文档里有加这一条 --hostname 192.168.1.8 ,实测可以不写,只需手动改配置
  • 若要运行企业版,只需把最后 gitlab/gitlab-ce:latest 改成 gitlab/gitlab-ee:latest
  • 等安装完成后运行命令获取管理员账号root密码
sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
  • 会返回一串密码: Password: akYzRtsctNfxnvVL2EFkK7wwvYXcQOi/spm2Yn/y77Y=

二、修改配置:

安装完成后,新建项目后,使用git-clone的时候会发现http和ssh的地址都不正确。所以要修改访问地址配置。

1、http访问地址修改

80端口的修改,我们需要在 gitlab.rb 文件中搜索 external_url

sudo vim /home/$USER/dockerfile/gitlab/etc/gitlab.rb

在后续文本中搜索输入命令 ?external_url 回车

?external_url
## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
##!
##! Note: During installation/upgrades, the value of the environment variable
##! EXTERNAL_URL will be used to populate/replace this value.
##! On AWS EC2 instances, we also attempt to fetch the public hostname/IP
##! address from AWS. For more details, see:
##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
# external_url 'GENERATED_EXTERNAL_URL'
external_url 'http://192.168.1.8:30002'

## Roles for multi-instance GitLab

2、ssh访问地址修改

gitlab.rb 文件中搜索 _ssh_port

sudo vim /home/$USER/dockerfile/gitlab/etc/gitlab.rb

在后续文本中搜索输入命令 ?_ssh_port 回车

?_ssh_port
### Wait for file system to be mounted
###! Docs: https://docs.gitlab.com/omnibus/settings/configuration.html#only-start-omnibus-gitlab-services-after-a-given-file-system-is-mounted
# high_availability['mountpoint'] = ["/var/opt/gitlab/git-data", "/var/opt/gitlab/gitlab-rails/shared"]

### GitLab Shell settings for GitLab
# gitlab_rails['gitlab_shell_ssh_port'] = 22
gitlab_rails['gitlab_ssh_host'] = '192.168.1.8'
gitlab_rails['gitlab_shell_ssh_port'] = 30001
# gitlab_rails['gitlab_shell_git_timeout'] = 800

### Extra customization
# gitlab_rails['extra_google_analytics_id'] = '_your_tracking_id'
# gitlab_rails['extra_google_tag_manager_id'] = '_your_tracking_id'
# gitlab_rails['extra_one_trust_id'] = '_your_one_trust_id'
3.生效配置:

进入gitlab容器

sudo docker exec -it gitlab /bin/sh

重载配置和重启gitlab

gitlab-ctl reconfigure && gitlab-ctl restart

也可以直接重启容器。

三、避坑

实测直接运行官方文档带有 --hostname 192.168.1.8 的docker run命令后,使用git-clone会报错404。
不带 --hostname 192.168.1.8 安装后修改配置,再重启时gitlab运行不起来。
此时进行如下操作可行:

0

评论 (0)

取消

您的IP: