Docker 部署 GitLab

Docker GitLab DevOps About 2,836 words

拉取镜像

https://hub.docker.com/r/gitlab/gitlab-ce

docker pull gitlab/gitlab-ce:14.6.1-ce.0

创建容器 - 指定 env

指定--env后可以省略后续的编辑文件以及重启。

docker run -d \
--name gitlab \
-u root \
-p 10022:22 \
-p 10080:80 \
-p 10443:443 \
--env GITLAB_OMNIBUS_CONFIG="external_url 'http://10.148.69.236/'; gitlab_rails['gitlab_ssh_host'] = '10.148.69.236';gitlab_rails['gitlab_shell_ssh_port'] = 10022" \
-v $PWD/gitlab/etc:/etc/gitlab \
-v $PWD/gitlab/log:/var/log/gitlab \
-v $PWD/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:14.6.1-ce.0

创建容器 - 不指定 env

不指定env需要后续的手动编辑文件以及重新配置和重启。

docker run -d \
--name gitlab \
-u root \
-p 10022:22 \
-p 10080:80 \
-p 10443:443 \
-v $PWD/gitlab/etc:/etc/gitlab \
-v $PWD/gitlab/log:/var/log/gitlab \
-v $PWD/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:14.6.1-ce.0

备注

如果指定的端口是54410080浏览器会抛出:ERR_UNSAFE_PORT不安全的端口错误,可以在浏览器的启动参数中添加以下参数:

--explicitly-allowed-ports=10080

宿主机开放端口

firewall-cmd --zone=public --add-port=10080/tcp --add-port=10022/tcp --add-port=10443/tcp --permanent
firewall-cmd --reload

进入容器

docker exec -it gitlab bash

编辑文件

编辑gitlab.rb

vi /etc/gitlab/gitlab.rb

或者使用命令:

docker exec -it gitlab editor /etc/gitlab/gitlab.rb

文件内容如下:

external_url 'http://192.168.100.1'

# 配置 ssh 协议所使用的访问地址和端口,同上
gitlab_rails['gitlab_ssh_host'] = '192.168.100.1'

# 此端口是运行时 22 端口映射的 10022 端口
gitlab_rails['gitlab_shell_ssh_port'] = 10022 

错误:配置的external_url必须是http开头的。

There was an error running gitlab-ctl reconfigure:

GitLab external URL must include a schema and FQDN, e.g. http://gitlab.example.com/

编辑gitlab.yml

vi /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

或者使用命令:

docker exec -it gitlab editor /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

原始配置

production: &base
  #
  # 1. GitLab app settings
  # ==========================

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 1b532ba3298f
    port: 80
    https: false

更改hostport

production: &base
  #
  # 1. GitLab app settings
  # ==========================

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 192.168.100.1
    port: 10080
    https: false

GitLab 相关命令

更新配置(该命令执行很耗时,6分多钟)

gitlab-ctl reconfigure

更新配置成功输出:

Running handlers:
Running handlers complete
Chef Infra Client finished, 7/735 resources updated in 06 minutes 54 seconds
gitlab Reconfigured!

重启

gitlab-ctl restart

查看状态

gitlab-ctl status

停止服务

gitlab-ctl stop

查看运行日志

gitlab-ctl tail

停止相关数据连接服务

gitlab-ctl stop unicorn
gitlab-ctl stop sideki

GitLab 默认用户名密码

用户名:root

默认密码:查看以下文件,文件24小时后删除

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

参考文档

https://docs.gitlab.com/ee/install/docker.html

相关网址

MIT Expat License

GitHub 镜像仓库: https://github.com/gitlabhq/gitlabhq

GitLab 原始仓库: https://gitlab.com/gitlab-org/gitlab

Views: 2,514 · Posted: 2022-02-12

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh