注意:提前安装dockerdocker-compose
  1. 首先编辑docker-compose.yml文件,内容如下:

    version: '3'
    
    services:
      gitlab:
        image: gitlab/gitlab-ce:latest
        container_name: gitlab
        restart: always
        hostname: 'gitlab.mydomain.com'
        environment:
          TZ: 'Asia/Shanghai'
          GITLAB_OMNIBUS_CONFIG: |
            external_url 'https://gitlab.mydomain.com'
        ports:
          - '8880:8880'
          - '4443:443'
          - '222:22'
        volumes:
          - ./gitlab/config:/etc/gitlab
          - ./gitlab/data:/var/opt/gitlab
          - ./gitlab/logs:/var/log/gitlab
        logging:
          driver: 'json-file'
          options:
            max-size: '2g'
    
    
  2. nginx配置

    sub_filter_once off; ### <--- 字符串进行多次替换
    sub_filter_types *; ### <--- 字符串替换生效的文件类型
    
    location / {
        proxy_set_header    X-Real-IP               $remote_addr;
        proxy_set_header    X-Forwarded-For         $proxy_add_x_forwarded_for;
        proxy_set_header    HTTP_X_FORWARDED_FOR    $remote_addr;
    
        proxy_pass https://127.0.0.1:4443; ### <--- 转发请求到 gitlab
    
        sub_filter '127.0.0.1:4443' 'gitlab.mydomain.com'; ### <--- 字符串替换
        sub_filter 'gitlab.mydomain.com:4443' 'gitlab.mydomain.com'; ### <--- 字符串替换
        sub_filter '[email protected]:' 'ssh://[email protected]:222/'; ### <--- 字符串替换
    }
    
  3. 默认登录账号

    用户名: root (注意不是 admin 哈)
    密码需要使用下面命令来匹配(该密码文件会在重装后的24小时后删除),也可以进入 docker 查看

    docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password