使用docker搭建gitlab

本文档详细介绍了如何使用Docker来部署gitlab-ce的15.11.4版本,包括手动创建PostgreSQL数据库、编辑docker-compose.yml文件以设置端口映射和数据卷,以及修改gitlab.rb配置文件以连接自定义数据库和配置SMTP邮件服务。在遇到SSH连接问题时,建议使用ssh://前缀的URL来克隆仓库。
摘要由CSDN通过智能技术生成

此文档使用 docker 搭建 gitlab-ce:15.11.4版本。

如果不是使用gitlab镜像自带的PostgreSQL数据库,那么就需要手动创建数据库表:

create user gitlab;
alter user gitlab password '123456';
create database gitlab;
alter database gitlab owner to gitlab;
\c gitlab
create extension "pg_trgm";

编辑docker-compose.yml 文件,内容如下:

version: '3'
services:
  gitlab:
    container_name: gitlab
    hostname: gitlab
    image: gitlab/gitlab-ce:15.11.4-ce.0
    ports:
      - "8081:8081"
      - "4422:22"
    restart:
      always
    #userns_mode:
    #  "host"
    volumes:
      - $PWD/config:/etc/gitlab
      - $PWD/logs:/var/log/gitlab
      - $PWD/data:/var/opt/gitlab
      - /etc/localtime:/etc/localtime:ro

启动docker-compose

docker compose up -d

编辑config/gitlab.rb文件,在最后追加配置:

external_url 'http://192.168.4.9:8081'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_email_from'] = "123456@qq.com"
gitlab_rails['gitlab_email_display_name'] = 'gitlab server'
gitlab_rails['gitlab_shell_ssh_port'] = 4422
postgresql['enable'] = true
gitlab_rails['db_adapter'] = "postgresql"
gitlab_rails['db_encoding'] = "utf8"
gitlab_rails['db_host'] = "192.168.1.240"
gitlab_rails['db_port'] = 5432
gitlab_rails['db_username'] = "gitlab"
gitlab_rails['db_password'] = "123456"
gitlab_rails['db_database'] = "gitlab"
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "123456@qq.com"
gitlab_rails['smtp_password'] = "suvywq"
gitlab_rails['smtp_domain'] = "qq.com.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_openssl_verify_mode'] = 'none'
puma['worker_processes'] = 2
prometheus['enable'] = false

更改完成后需要在容器内重新加载配置文件:

gitlab-ctl reconfigure

如果reconfigure成功,最后会提示gitlab Reconfigured!

之后可以通过浏览器访问 GitLab,账号 root,默认密码在/etc/gitlab/initial_root_password

在/etc/crontab里设置gitlab备份:

# gitlab backup
00 06 * * * root /usr/bin/docker exec gitlab gitlab-rake gitlab:backup:create >> /data/docker_data/gitlab/data/backups/backup.log
00 06 * * * root /usr/bin/find /data/docker_data/gitlab/data/backups -name '*.tar' -mtime +30 | /usr/bin/xargs rm -f

注意:当使用git 连接gitlab的非22端口的SSH服务时如发现需要输入密码,私钥无法使用,或者出现以下提示:

stderr: Warning: Permanently added '192.168.4.9' (ECDSA) to the list of known hosts.
Permission denied, please try again.
Permission denied, please try again.
git@192.168.4.9: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository.

就要使用新的方式,在git地址前面加上ssh://,比如:

git clone ssh://git@hostname:port/.../xxx.git
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值