首页 > 解决方案 > 使用 Docker-Compose 文件安装 GitLab-CE - Ssh git 用户询问密码

问题描述

Docker-Compose file我已经在我的 Docker 主机服务器上使用以下链接成功安装了 GitLab-CE 版本。

https://docs.gitlab.com/omnibus/docker/#install-gitlab-using-docker-compose

我的docker-compose.yml内容如下。

web:
  image: 'gitlab/gitlab-ce:latest'
  restart: always
  hostname: 'gitlab.example.com'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'https://gitlab.example.com'
      gitlab_rails['gitlab_shell_ssh_port'] = 2223
  ports:
    - '80:80'
    - '443:443'
    - '2223:22'
  volumes:
    - '$GITLAB_HOME/gitlab/config:/etc/gitlab'
    - '$GITLAB_HOME/gitlab/logs:/var/log/gitlab'
    - '$GITLAB_HOME/gitlab/data:/var/opt/gitlab'

在我的一个 Ubuntu 客户端系统中,当我运行ssh -T -p 2223 git@gitlab.example.com它时它可以工作(它显示Welcome to GitLab)。gitlab_rails['gitlab_shell_ssh_port'] = 2223而在我的 docker 主机中,如果我gitlab.rb在运行gitlab-ctl reconfigure. 如果我再次运行ssh -T git@gitlab.example.com它,它会询问git用户的密码。

Docker-Server 的 22 端口监听如下。

netstat -tulnp | grep :22
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1516/sshd
tcp6       0      0 :::2222                 :::*                    LISTEN      2587/docker-proxy
tcp6       0      0 :::22                   :::*                    LISTEN      1516/sshd

由于sshd服务已经22在我的 docker 服务器上的端口上运行,那么有没有办法使用 22 默认端口来克隆我们的 GitLab 存储库?无需更改 sshd 默认端口。就像下面的示例命令一样,我想克隆。所以任何建议都会有所帮助。

git clone git@gitlab.example.com:sample-group/sample.git

@Exadra37,我已经更新了您共享的数据并尝试重建,但它失败了。

[root@gitlab]# docker-compose up --build
WARNING: The SSH_AUTH_SOCK variable is not set. Defaulting to a blank string.
Recreating 486bb3cb8496_docker-gitlab-ce_web_1 ... error

ERROR: for 486bb3cb8496_docker-gitlab-ce_web_1  Cannot create container for service web: create .: volume name is too short, names should be at least two alphanumeric characters

ERROR: for web  Cannot create container for service web: create .: volume name is too short, names should be at least two alphanumeric characters
ERROR: Encountered errors while bringing up the project.

标签: docker-composegitlab-ce

解决方案


您需要将 ssh 套接字映射到容器中。

将以下内容添加到您的docker-compose.yml文件中:

environment:
  - SSH_AUTH_SOCK=/ssh-agent
volumes:
  - $SSH_AUTH_SOCK:/ssh-agent

推荐阅读