I'm unable to docker-compose successfully on a remote host using SSH from a gitlab CI/CD pipeline runner.
docker-compose fails with the following errors:
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'))
I'm not able to repro the issue outside Gitlab. Meaning, I tried on my local machine by running the same docker image my gitlab deploy step use, do the exact same commands in my script manually and it worked like a charm...
I'm even trying the ssh config in the script by connecting to the host and printing docker version
and it succeeds properly.
#!/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
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
Thanks for your help
I had this exact problem, depending on your configuration it might work or not. Basically, i created a user deployer
on my server which I was trying to ssh to.
Since i had forgotten to add this new user ( deployer
) to the docker
usergroup, he had no docker permissions. So basically all I did was
[root@myserver ~]# groupadd docker
groupadd: group 'docker' already exists
[root@myserver ~]# usermod -aG docker deployer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.