本文的 Docker 版 Gitlab 是基于docker-compose方式进行安装,其基本配置如下:

version: "3.9"
services:
  gitlab:
    container_name: gitlab
    image: "gitlab/gitlab-ce:14.2.3-ce.0"
    restart: always
    hostname: "gitlab.fe.sw"
    environment:
      TZ: "Asia/Shanghai"
      GITLAB_OMNIBUS_CONFIG: |
        external_url = "gitlab.fe.sw"
    ports:
      - "9000:80"
      - "9022:22"
    volumes:
      - "/backups/gitlab:/backups"
      - "/opt/dockers/gitlab/config:/etc/gitlab"
      - "/opt/dockers/gitlab/logs:/var/log/gitlab"
      - "/opt/dockers/gitlab/data:/var/opt/gitlab"

如下图,根本不能通过显示的 ssh/http 地址进行正常 git clone,必须调整 git 地址。

E89mLr

HTTP 协议

根据上面的配置信息,正确的 http url 是:http://gitlab.fe.sw:9000/root/test.git,效果如下

UJ8UPy

强迫症表示受不了,带个端口干啥?马上用 Nginx 做一个反向代理,配置如下:

  server {
    listen 80;
    server_name gitlab.fe.sw;

    location / {
      proxy_pass <http://localhost:9000/>;
    }
  }

然后就可以 http 方式就可以改为:http://gitlab.fe.sw/root/test.git,完美!

git 协议

同样的,目前阶段要通过 git 协议是不行的,只能借助ssh的,所以正确的 git url 是:ssh://git@gitlab.fe.sw:9022/root/test.git,效果如下

y7Hx3O

这里为啥说要借助ssh,可以参考聊聊 Git 的三种传输协议及实现

刚才 http 中多了一个端口都不行,更别说现在还改了协议!!马上研究。先贴参考资料,大家可以先自己研究: