Gitlab-CI DinD无法启动

时间:2018-08-21 23:02:39

标签: docker docker-compose gitlab gitlab-ci gitlab-ci-runner

我正在尝试将DinD(Docker中的Docker)与我的Gitlab-CI构建脚本一起使用,无论我进行什么更改,我始终会遇到相同的错误。我在做什么错了?

错误

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"
}

--- 编辑 ---

对于任何回来看看这个的人来说,这就是我如何使其工作的。在提交回购协议之前,我正在本地计算机上运行gitlab-runner进行测试。

运行命令时:

gitlab-runner exec docker django_build

无论出于何种原因,它都不使用我的配置文件。我找到了此链接:https://gitlab.com/gitlab-org/gitlab-runner/issues/1791指出您必须在命令中-docker特权

运行后:

gitlab-runner exec docker --docker-privileged django_build

一切正常。

1 个答案:

答案 0 :(得分:0)

仔细检查GitLab runner parameters when running docker

尤其要确保将gitlab-runner用户添加到docker组:

sudo usermod -aG docker gitlab-runner

从那里开始,sudo -u gitlab-runner -H docker info应该起作用。

如果不是,请检查/etc/hosts is mounted as a volume, as in this bug


官方gitlab-runner documentation声明,对于DiD执行者,使用

创建一个config.toml。
[[runners]]
  url = "https://gitlab.com/"
  token = TOKEN
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = true

但是OP发现privileged = true没有被使用。
除非config.tml是由sudo gitlab-runner register -n... --docker-privileged命令创建的。

如果没有,则需要gitlab-runner exec docker --docker-privileged