Docker Compose部署Gitlab

Gitlab总共有两个版本一个是社区版一个是企业版,两个版本功能上基本没区别但企业版要去Gitlab官方买授权证书要花钱所以我们选择社区版已经够用了的基本上满足中小型企业及个人

我们登录服务器创建Gitlab目录及docker-compose.yml

mkdir gitlab
cd gitlab
touch docker-compose.yaml

配置文件

docker-compose.yml配置文件

version: '3.3'
services:
    gitlab:
      image: 'gitlab/gitlab-ce:latest'
      container_name: 'gitlab'
      restart: always
      hostname: 'gitlab' #填写计算机名即可
      environment:
        TZ: 'Asia/Shanghai'
        GITLAB_OMNIBUS_CONFIG: |
         external_url 'https://mqthub.com'  #访问地址
         # HTTPS配置
         nginx['enable'] = true
         nginx['redirect_http_to_https']= true
         nginx['ssl_certificate']= "/home/cert/mqthub.com/mqthub.com.pem"
         nginx['ssl_certificate_key']= "/home/cert/mqthub.com.com/mqthub.com.key"
         # 端口配置
         gitlab_rails['gitlab_shell_ssh_port'] = 2222
         unicorn['port'] = 8880
         # Email配置
         gitlab_rails['smtp_enable'] = true
         gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
         gitlab_rails['smtp_port'] = 465
         gitlab_rails['smtp_user_name'] = "noreply@mqtian.com"
         gitlab_rails['smtp_password'] = "xxx"
         gitlab_rails['smtp_authentication'] = "login"
         gitlab_rails['smtp_enable_starttls_auto'] = true
         gitlab_rails['smtp_tls'] = true
         gitlab_rails['gitlab_email_from'] = 'noreply@mqtian.com'
      ports:
        - '80:80'        #http端口
        - '443:443'   #https端口
        - '222:22'   #配置222端口转发到容器的22端口上
      volumes:
        - ./etc:/etc/gitlab             #Gitlab配置文件目录
        - ./data:/var/opt/gitlab  #Gitlab数据目录
        - ./logs:/var/log/gitlab   #Gitlab日志目录
        - ~/cert/:/home/cert/    #域名SSL证书目录
        - /etc/localtime:/etc/localtime:ro  #同步宿主机日期时间到容器

启动Gitlab

docker-compose up -d  # 启动
docker-compose stop  # 停止
docker-compose start # 启动
docker-compose restart # 重启
docker-compose down # 停止容器并移除

访问Gitlab

我们安装完Gitlab后第一次访问会重定向到root用户重置密码界面重置完密码后使用root+刚刚设置的密码登录即可

我的Gitlab是配置了Github账号快速登录的如需要配置的话请直接在本站留言评论

在这里插入图片描述

Q.E.D.