1

I have set up a simple .gitlab-ci file which should be able to run docker service:

docker:
  image: google/cloud-sdk:latest
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_HOST: tcp://127.0.0.1:2375
  services:
    - docker:dind
  tags:
    - docker
  script:
    - docker pull buster-slim

However it fails as:

https://gitlab.com/knyttl/runnerdemo/-/jobs/932204050

2020-12-25T19:31:04.558361767Z time="2020-12-25T19:31:04.558195638Z" level=info msg="API listen on [::]:2375"
2020-12-25T19:31:04.558522591Z time="2020-12-25T19:31:04.558447616Z" level=info msg="API listen on /var/run/docker.sock"

The service apparently correctly starts, but then it doesn't work:

Cannot connect to the Docker daemon at tcp://127.0.0.1:2375. Is the docker daemon running?
Vojtěch
  • 11,312
  • 31
  • 103
  • 173

3 Answers3

2

The problem comes from the fact that the docker daemon is not part of the image google/cloud-sdk/ that you specify for this job. You should create your own image with the google/cloud-sdk as a base image. You can also install & start docker in the before_script section of the job. See the doc on DockerHub for the image you use:

Installing additional components

By default, all gcloud components are installed on the default images (google/cloud-sdk:latest and google/cloud-sdk:VERSION). The google/cloud-sdk:slim and google/cloud-sdk:alpine images do not contain additional components pre-installed.

You can extend these images by following the instructions below: Debian-based images

cd debian_slim/
docker build --build-arg CLOUD_SDK_VERSION=159.0.0
    --build-arg INSTALL_COMPONENTS="google-cloud-sdk-datastore-emulator" \
    -t my-cloud-sdk-docker:slim .`
aboitier
  • 180
  • 11
1

The image which can use DIND is docker:dind, not necessarily google/cloud-sdk:latest, so your .gitlab-ci.yml wuold look like:

docker:
  image: docker:dind
  variables:
    DOCKER_DRIVER: overlay2
  services:
    - docker:dind
  tags:
    - docker
  script:
    - docker pull buster-slim
    # ...
    # I don't know what needs to be built...

You can check this tutorial for a step by step recipe.

emi
  • 2,786
  • 1
  • 16
  • 24
1

In fact, the only reason why this was not working was:

 DOCKER_HOST: tcp://docker:2375

The dind service CAN run within cloud-sdk image, but it needs to be linked as a host.

Vojtěch
  • 11,312
  • 31
  • 103
  • 173