Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab-CI DinD will not start

I'm trying to use DinD (Docker in Docker) with my Gitlab-CI build script and I keep getting the same error not matter what I change. What am I doing wrong?

Errors

Service container logs: 
2018-08-21T22:54:00.129660274Z mount: permission denied (are you root?)
2018-08-21T22:54:00.129701426Z Could not mount /sys/kernel/security.
2018-08-21T22:54:00.129706380Z AppArmor detection and --privileged mode might break.
2018-08-21T22:54:00.130334774Z mount: permission denied (are you root?)
...
$ docker info
error during connect: Get http://docker:2375/v1.38/info: dial tcp: lookup docker on 8.8.8.8:53: no such host

gitlab-ci.yml

django_build:
  stage: build
  variables:
    DOCKER_HOST: tcp://docker:2375/
    DOCKER_DRIVER: overlay2
  image: docker:stable
  services:
    - docker:dind
  before_script:
    - docker info
  script:
    - echo "Building something." 

gitlab-runner config.toml

concurrent = 1 
check_interval = 0 

[[runners]]
  name = "###"
  url = "###"
  token = "###"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "alpine:3.4"
    privileged = true
    disable_cache = false
    volumes = ["/cache"]
  [runners.cache]
    Insecure = false

/etc/docker/daemon.json

{
    "storage-driver": "overlay2"
}

---EDIT---

For anyone that comes back to look at this here's how I got it working. I was running the gitlab-runner on my local machine to test things before committing to the repo.

When running the command:

gitlab-runner exec docker django_build

for whatever reason it wasn't using my config file. I found this link: https://gitlab.com/gitlab-org/gitlab-runner/issues/1791 stating that you have to out --docker-privileged in the command.

After running:

gitlab-runner exec docker --docker-privileged django_build

everything worked.

like image 773
Mike A. Avatar asked Aug 21 '18 23:08

Mike A.


1 Answers

Double-check the GitLab runner parameters when running docker.

In particular, do make sure the gitlab-runner user is added to docker group:

sudo usermod -aG docker gitlab-runner

From there, sudo -u gitlab-runner -H docker info should work.

If not, check if the /etc/hosts is mounted as a volume, as in this bug.


The official gitlab-runner documentation states, for DiD executor, to create a config.toml with

[[runners]]
  url = "https://gitlab.com/"
  token = TOKEN
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = true

But the OP has found the privileged = true is not used.
Unless maybe if the config.tml was created by a sudo gitlab-runner register -n... --docker-privileged command.

If not, gitlab-runner exec docker --docker-privileged is needed.

like image 167
VonC Avatar answered Nov 15 '22 03:11

VonC