服务器 > 服务器 > 云虚拟主机

如何使用docker compose安装gitlab

36人参与 2025-02-15 云虚拟主机

gitlab简介

gitlab是一个基于git的开源项目,旨在帮助团队更高效地合作和开发软件。它使用ruby on rails框架构建,提供了一个自托管的git仓库管理工具,支持版本控制、代码审查、持续集成和持续部署等功能。

主要功能包括:

- 版本控制:用户可以创建分支、合并代码,并处理冲突,确保代码的历史和变更管理得当。
- 代码审查:团队成员可以通过拉取请求(pull requests)对提交的代码进行评论和讨论,确保代码质量。
- 持续集成/持续部署(ci/cd):gitlab内置了ci/cd功能,支持自动化的构建、测试和部署流程,提高开发效率。
- 项目管理:通过issue跟踪、看板、里程碑等功能,帮助团队管理项目进度和任务。

gitlab还提供了权限管理和审计日志,确保代码的安全性和合规性,适用于从小型开源项目到大型企业级应用的各种规模团队。
gitlab是实现 devops 自动化开发运维流水线的经典工具。

设置gitlab_home路径

先设置一个 gitlab_home 环境变量,为gitlab的工作目录。有2个方式:

通过第2种方式添加配置后,使用 source ~/.bash_profile 命令,使配置生效

创建docker挂载目录

进入上一步骤设置的 $gitlab_home 目录中,新建 data, logs, config 个文件夹。

如下所示:

宿主机目录

容器内部目录

说明

$gitlab_home/data

/var/opt/gitlab

stores application data.

$gitlab_home/logs

/var/log/gitlab

stores logs.

$gitlab_home/config

/etc/gitlab

stores the gitlab configuration files.

获取可用的gitlab版本

# 镜像名格式:
gitlab/gitlab-ce:<version>-ce.0
# 指定固定版本镜像
gitlab/gitlab-ce:17.6.2-ce.0
# 使用最新版本镜像
gitlab/gitlab-ce:latest

编写docker-compose.yml文件

docker-compose.yml:

version: '3.6'
services:
  gitlab:
    image: gitlab/gitlab-ce:17.6.2-ce.0
    container_name: gitlab
    restart: always
    hostname: 'gitlab.example.com'
    environment:
      gitlab_omnibus_config: |
        external_url 'http://gitlab.example.com:8929'
        gitlab_rails['gitlab_shell_ssh_port'] = 2424
    ports:
      - '8929:8929'
      - '443:443'
      - '2424:22'
    volumes:
      - '$gitlab_home/config:/etc/gitlab'
      - '$gitlab_home/logs:/var/log/gitlab'
      - '$gitlab_home/data:/var/opt/gitlab'
    shm_size: '256m'

通过 gitlab_omnibus_config 环境变量,配置 external_url 参数,设定仓库的http地址。

ports 的端口映射,以 gitlab_omnibus_config 的相关配置项为准。

启动docker

docker compose up -d

容器首次启动,需要数分钟的时间,请耐心等待。
启动成功后,容器状态由 (health: starting) 变为 (healthy)。如下所示:

name      image                          command             service   created       status                             ports
gitlab    gitlab/gitlab-ce:17.6.2-ce.0   "/assets/wrapper"   gitlab    2 hours ago   up 12 seconds (health: starting)   0.0.0.0:443->443/tcp, :::443->443/tcp, 80/tcp, 0.0.0.0:8929->8929/tcp, :::8929->8929/tcp, 0.0.0.0:2424->22/tcp, [::]:2424->22/tcp
name      image                          command             service   created       status                    ports
gitlab    gitlab/gitlab-ce:17.6.2-ce.0   "/assets/wrapper"   gitlab    3 hours ago   up 51 minutes (healthy)   0.0.0.0:443->443/tcp, :::443->443/tcp, 80/tcp, 0.0.0.0:8929->8929/tcp, :::8929->8929/tcp, 0.0.0.0:2424->22/tcp, [::]:2424->22/tcp

查看容器运行日志:

sudo docker logs -f gitlab

通过前面配置的 external_url,访问 gitlab 项目地址,登录root账号。

注:the password file is automatically deleted in the first container restart after 24 hours.

基础配置

gitlab_omnibus_config

gitlab_omnibus_config 环境变量,允许预设 gitlab.rb 文件的配置项。
具有以下特点:

配置可包含 gitlab项目地址,数据库配置等。具体请见: gitlab.rb文件配置模板

external_url:项目主页。如:"http://gitlab.example.com:8929"gitlab_rails['gitlab_shell_ssh_port']:ssh端口。如:2424gitlab_rails['initial_root_password']: 项目初始化时,预设的root用户密码。

项目首次启动时,也可在容器内注入环境变量 gitlab_root_password ,预设 root 用户的登录密码。

docker运行命令如下所示:

sudo docker run --detach 

–hostname gitlab.example.com
–env gitlab_omnibus_config=“external_url ‘http://gitlab.example.com:8929’; gitlab_rails[‘gitlab_shell_ssh_port’] = 2424”
–publish 8929:8929 --publish 2424:22
–name gitlab
–restart always
–volume $gitlab_home/config:/etc/gitlab
–volume $gitlab_home/logs:/var/log/gitlab
–volume $gitlab_home/data:/var/opt/gitlab
–shm-size 256m
gitlab/gitlab-ce:-ce.0

修改配置

​​​​​​​ 中文设置

用户个性化设置:点击左上角用户头像,下拉框选择 preferences。页面找到 localization - language

当前用户,一定是更改 用户个性化设置,才能生效:

在页面右上方的用户菜单中,选择“settings”。
进入settings页面后,点击左侧导航栏中的“preferences”选项。
在preferences页面中,找到“localization”区域,将“language”选项修改为“简体中文”。
点击页面下方的“save changes”按钮,保存语言设置。

数据库配置

gitlab 16.0 起,gitlab默认使用2个数据库连接。我们可以禁用,回到原始的单连接模式。

sudo docker exec -it gitlab editor /etc/gitlab/gitlab.rb
gitlab_rails['databases']['ci']['enable'] = false
sudo docker restart gitlab

系统邮箱配置

修改配置文件:/etc/gitlab/gitlab.rb

重载配置,使其生效:gitlab-ctl reconfigure

gitlab_rails[‘smtp_enable’] = true
gitlab_rails[‘smtp_address’] = “smtp.server”
gitlab_rails[‘smtp_port’] = 465
gitlab_rails[‘smtp_user_name’] = “smtp user”
gitlab_rails[‘smtp_password’] = “smtp password”
gitlab_rails[‘smtp_domain’] = “example.com”
gitlab_rails[‘smtp_authentication’] = “login”
gitlab_rails[‘smtp_enable_starttls_auto’] = true
gitlab_rails[‘smtp_openssl_verify_mode’] = ‘peer’

if your smtp server does not like the default ‘from: gitlab@localhost’ you can change the ‘from’ with this setting.

gitlab_rails[‘gitlab_email_from’] = ‘gitlab@example.com’
gitlab_rails[‘gitlab_email_reply_to’] = ‘noreply@example.com’

if your smtp server is using a self signed certificate or a certificate which is signed by a ca which is not trusted by default, you can specify a custom ca file. please note that the certificates from /etc/gitlab/trusted-certs/ are not used for the verification of the smtp server certificate.

gitlab_rails[‘smtp_ca_file’] = ‘/path/to/your/cacert.pem’

示例:qq exmail (腾讯企业邮箱)

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxx@xx.com"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxx@xx.com'
gitlab_rails['smtp_domain'] = "exmail.qq.com"

https://docs.gitlab.com/17.6/ee/install/docker/installation.html
steps after installing gitlab: https://docs.gitlab.com/17.6/ee/install/next_steps.html

到此这篇关于使用docker compose安装gitlab的文章就介绍到这了,更多相关docker compose安装gitlab内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)
打赏 微信扫一扫 微信扫一扫

您想发表意见!!点此发布评论

推荐阅读

设置docker的定时关闭和启动方式

02-15

Docker 镜像加速访问的几种方法

02-15

Windows的docker删除容器后WSL2磁盘空间不释放的问题的解决方法

02-15

Docker Compose安装本地maven方式

02-15

通过Docker运行AnythingLLM的方法

02-15

docker部署微信小程序自动构建发布和更新的详细步骤

02-15

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论