【发布时间】:2021-05-04 00:01:39
【问题描述】:
我无法使用来自 gitlab CI/CD 管道运行器的 SSH 在远程主机上成功 docker-compose。
docker-compose 失败并出现以下错误:
http.client.RemoteDisconnected: Remote end closed connection without response
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
我无法在 Gitlab 之外重现该问题。意思是,我尝试在本地机器上运行我的 gitlab 部署步骤使用的相同 docker 映像,在我的脚本中手动执行完全相同的命令,它就像一个魅力......
我什至通过连接到主机并打印 docker version 来尝试脚本中的 ssh 配置,并且成功成功。
deploy_to_staging.sh
#!/bin/bash
apk update
apk add openssh-client
apk add --update bash
eval $(ssh-agent -s)
mkdir -p ~/.ssh
chmod 600 ~/.ssh
# copy the server private key
echo "$SSH_PRIVATE_KEY"
echo "$SSH_PRIVATE_KEY" | ssh-add -
# copy server host key .pub file from /etc/ssh/ and paste it into this variable
echo "$SSH_SERVER_HOSTKEYS"
ssh-keyscan -p 12345 11.222.3.444
ssh-keyscan -p 12345 11.222.3.444 >> ~/.ssh/known_hosts
ssh root@11.222.3.444 -p 12345 "docker version; exit"
# Docker-compose app and db
docker-compose --verbose -H "ssh://root@11.222.3.444:12345" -f docker-compose.staging.yml up -d --build
exit
gitlab-ci.yml
image: alpine:latest
services:
- docker:dind
stages:
- build
- package
- deploy
[...]
deploy:
image: docker/compose:alpine-1.28.2
stage: deploy
environment:
name: staging
only:
- master
script:
- sh deploy_to_staging.sh
感谢您的帮助
【问题讨论】:
-
您找出问题所在了吗?我有类似的问题..
-
@kodlan 不幸的是没有。我无法在 Gitlab 之外重现这个问题,所以我被困住了......
标签: docker ssh docker-compose gitlab gitlab-ci