Docker can';不要将ssh与停靠的Gitlab一起使用

Docker can';不要将ssh与停靠的Gitlab一起使用,docker,ssh,gitlab,Docker,Ssh,Gitlab,我已经在centos 7上使用docker安装了最新的gitlab docker run -d --hostname git.xxxx.com \ -p 8082:80 -p 22:22 \ --name gitlab \ --restart always \ -v /srv/gitlab/config:/etc/gitlab:Z \ -v /srv/gitlab/logs:/var/log/gitlab:Z \ -v /srv/gitlab/data:/var/opt/gitlab:Z \ g

我已经在centos 7上使用docker安装了最新的gitlab

docker run -d --hostname git.xxxx.com \
-p 8082:80 -p 22:22 \
--name gitlab \
--restart always \
-v /srv/gitlab/config:/etc/gitlab:Z \
-v /srv/gitlab/logs:/var/log/gitlab:Z \
-v /srv/gitlab/data:/var/opt/gitlab:Z \
gitlab/gitlab-ce:latest
我还将主机ssh端口更改为10022,并让gitlab使用端口22。 Gitlab运行成功。克隆使用http工作,但在使用ssh时失败

git clone git@git.xxxx.com:yphc/dt-dd-miniprogram.git

Cloning into 'dt-dd-miniprogram'...
ssh: connect to host git.xxxx.com port 22: Bad file number
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
检查Gitlab状态的输出:

root@git:/# gitlab-ctl status
run: gitaly: (pid 472) 241405s; run: log: (pid 467) 241405s
run: gitlab-monitor: (pid 474) 241405s; run: log: (pid 465) 241405s
run: gitlab-workhorse: (pid 471) 241405s; run: log: (pid 464) 241405s
run: logrotate: (pid 15611) 203s; run: log: (pid 456) 241405s
run: nginx: (pid 475) 241405s; run: log: (pid 469) 241405s
run: node-exporter: (pid 460) 241406s; run: log: (pid 459) 241406s
run: postgres-exporter: (pid 453) 241406s; run: log: (pid 452) 241406s
run: postgresql: (pid 470) 241406s; run: log: (pid 463) 241406s
run: prometheus: (pid 482) 241406s; run: log: (pid 476) 241406s
run: redis: (pid 396) 241408s; run: log: (pid 395) 241408s
run: redis-exporter: (pid 455) 241406s; run: log: (pid 454) 241406s
run: sidekiq: (pid 473) 241406s; run: log: (pid 468) 241406s
warning: sshd: unable to open supervise/ok: access denied
run: unicorn: (pid 466) 241406s; run: log: (pid 458) 241406s
警告:sshd:无法打开监控/ok:访问被拒绝

我在gitlab容器中尝试了ssh命令,该命令有效。我还将端口22添加到防火墙

[root@localhost zones]# firewall-cmd --list-all 
    public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp2s0
  sources: 
  services: ssh dhcpv6-client
  ports: 2022/tcp 10022/tcp 22/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
当我关闭防火墙时,它会说

    Cloning into 'dt-dd-miniprogram'...
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我在网上找了很长时间,但什么也没找到。如果您能提供任何帮助或想法来解决这个问题,我将不胜感激。

我从kvm迁移到gitlab ce docker官方镜像后,也遇到了同样的情况

root@gitlab:/opt/gitlab# /opt/gitlab/embedded/bin/sv start sshd
warning: sshd: unable to open supervise/ok: access denied
我发现这个sv会产生错误:

root@gitlab:/opt/gitlab# /opt/gitlab/embedded/bin/sv start sshd
warning: sshd: unable to open supervise/ok: access denied
因为root用户无法访问/opt/gitlab/sv/sshd/supervise/ok管道:

root@gitlab:/opt/gitlab/sv/sshd/supervise# cat ok
cat: ok: Permission denied
作为一个测试,我已经用777个权限更新了它,但仍然不走运

root@gitlab:/opt/gitlab/# /opt/gitlab/embedded/bin/sv start sshd
fail: sshd: runsv not running
我使用的变通方法是在基于gitlab ce:latest的Dockerfile中:

RUN sed -i '/gitlab-ctl reconfigure/a service ssh start' /assets/wrapper
这将启动ssh,现在我可以通过ssh与git用户连接以推拉:)

不要忘记,您需要为要使用的端口设置适当的环境


所以现在一切正常,但请记住,这是一个奇怪/丑陋的解决方法,我确信有更好的方法来实现这一点。

我在另一个centos 7上也做了同样的事情,一切正常,所以我猜操作系统有一些错误,gitlab docker正常,但我到目前为止还找不到它
thx

让一台主机上的两台服务器使用同一端口的最简单方法是将它们绑定到单独的IP地址。默认情况下,
gitlab
sshd
都绑定到
0.0.0
,因此在所有地址和接口上保留该端口

主机提供商可以为您的计算机分配额外的公共ip地址,他们应该在主机上的
ifconfig
中注册

本地ssh服务器应绑定到主ip地址。在
/etc/ssh/sshd\u config
中查找

ListenAddress 0.0.0.0
Docker可以使用
-p:22:22


您可以为辅助ip设置子域,例如
git.example.com
,为主ip设置
server.example.com

检查另一种选择,当然,是在系统前面放置TCP负载平衡器。
ListenAddress 0.0.0.0