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 22.214.171.1244 ssh-keyscan -p 12345 126.96.36.1994 >> ~/.ssh/known_hosts ssh firstname.lastname@example.org -p 12345 "docker version; exit" # Docker-compose app and db docker-compose --verbose -H "ssh://email@example.com: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