2

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.

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 [email protected] -p 12345 "docker version; exit"

# Docker-compose app and db
docker-compose --verbose -H "ssh://[email protected]: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

Thanks for your help

2
  • did you find out what the problem was? I'm having similar issues.. Commented Feb 4, 2021 at 19:19
  • @kodlan unfortunately no. I can't reproduce this issue outside Gitlab so I'm stuck... Commented Feb 5, 2021 at 14:02

1 Answer 1

0

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.