I am trying to have a Docker image deployed to my server by GitLab CI, but it only worked once¹ and then dies with the error message below. Here is the .gitlab-ci.yml snippet:

  image: docker:latest
    - docker:dind
    DOCKER_HOST: ssh://gitlab-ci@$DEPLOY_HOST
    - eval $(ssh-agent -s)
    - echo "${SSH_KEY}" | ssh-add -
    - mkdir -p ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    - echo $CI_JOB_TOKEN | docker login --username gitlab-ci-token --password-stdin $CI_REGISTRY;
    - docker pull "$CI_REGISTRY_IMAGE"
    - docker run --name mycontainer --detach $CI_REGISTRY_IMAGE
    - docker logout $CI_REGISTRY

The error in the job log looks like that:

Executing "step_script" stage of the job script 00:04
Using docker image sha256:51453dcdd9bd51e503f75e6d42a4071469ad2ba816321781985041b6bc7776db for docker:latest with digest docker@sha256:ddf0d732dcbc3e2087836e06e50cc97e21bfb002a49c7d0fe767f6c31e01d65f ...
$ eval $(ssh-agent -s)
Agent pid 18
$ echo "${SSH_KEY}" | ssh-add -
Identity added: (stdin) (gitlab-ci@jacks)
$ mkdir -p ~/.ssh
$ [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
$ echo $CI_JOB_TOKEN | docker login --username gitlab-ci-token --password-stdin $CI_REGISTRY;
error during connect: Post "http://docker.example.com/v1.24/auth": command [ssh -l gitlab-ci -- xxx.xxx.xxx.xxx docker system dial-stdio] has exited with exit status 255, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=ssh: connect to host xxx.xxx.xxx.xxx port 22: Connection refused

While I x-ed out the IP address of the destination server in this post (which is the value of the DEPLOY_HOST env var), it literally says docker.example.com in the error message.

So my question would be, where that example string comes from.

This is on a self-hosted GitLab instance and the runner is also self-hosted on a server that is neither the destination host, nor the one where GitLab runs on.

¹ The connection issue itself seems to be a problem with the SSH connection and not related to the CI/CD pipeline config.

  • Post "http://docker.example.com/v1.24/auth" is likely coming from docker login --username gitlab-ci-token --password-stdin $CI_REGISTRY; - what's the value of $CI_REGISTRY Sep 12 at 20:13
  • The value of $CI_REGISTRY is the container registry. It is a pre-defined variable that is specific to every project and defined automatically by GitLab CI, see docs.gitlab.com/ee/ci/variables/predefined_variables.html (sorry for answering late)
    – mcnesium
    Nov 24 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.