Search code examples
dockergitlab-cigitlab-ci-runner

Gitlab runner using dind results in error server misbehaved


I've been trying to get docker up and running in gitlab-runner but keep getting errors such as one below or Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

.gitlab-ci.yml

build:
  stage: build
  image: docker:latest
  services:
  - name: docker:dind
    alias: docker
    entrypoint: ["env", "-u", "DOCKER_HOST"]
    command: ["dockerd-entrypoint.sh"]
  variables:
    DOCKER_HOST: tcp://docker:2375/
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - docker info

results:

$ docker info
Client:
 Debug Mode: false

Server:
ERROR: error during connect: Get http://docker:2375/v1.40/info: dial tcp: lookup docker on 10.233.0.3:53: server misbehaving
errors pretty printing info

Runner is not in privileged mode. Is there a way to build a docker image in runner without privileged mode?

And if no, are there other practices and what important cons does this flag bring?


Solution

  • Haven't managed to get dind working so I've come across kaniko tool and managed to build image push it to gitlab repository and use it in other jobs in this pipeline.

    Narrowed down definition of this job in gitlab-ci.yml:

    build:
      stage: build
      image:
        name: gcr.io/kaniko-project/executor:debug
        entrypoint: [""]
      script:
        - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
        - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE
    

    Gitlab's documentation.