我正在尝试使用Gitlab Docker运行器构建Docker映像。

为此,我在/etc/gitlab-runner/config.toml中为运行程序配置了一个名为/ builds的共享卷:

concurrent = 1
check_interval = 0

[[runners]]
  name = "My Docker Runner"
  url = "http://host"
  token = "xxxxxxxxxxxxxxxxxxxx"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:latest"
    privileged = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache", "/builds"]
  [runners.cache]


我在回购中创建了一个.gitlab-ci.yml,它看起来大致像这样:

image: alpine:latest

variables:
  GIT_STRATEGY: none

test_ci:
  script:
    - apk update
    - apk add docker
    - apk add git
    - docker info
    - git clone http://gitlab-ci-token:${CI_JOB_TOKEN}@host/user/repo.git /builds/user/repo
    - docker build -t database .
    - docker run database


我还在回购中创建了一个Dockerfile,如下所示:

FROM postgres:9.6

ADD /builds/user/repo/script.sql /docker-entrypoint-initdb.d/


一切正常,除了Docker ADD指令失败,因为它找不到/builds/user/repo/script.sql:

ADD failed: stat /var/lib/docker/tmp/docker-builder886348850/builds/user/repo/script.sql: no such file or directory


所以我想我试图在容器之间共享的/ build卷无法正常工作,因为我希望它能...有人可以帮我这个忙吗?我希望能够将在转轮容器上克隆的代码共享给docker build命令,然后再共享给新创建的容器。

评论

您应该在docker build命令之前添加ls -alh / builds / user / repo以确保文件至少在容器中存在,并可能通过添加sleep 60来检查主机上目录的内容来继续调试,就像您也挂载了docker.sock一样。

文件在那里。实际上,/ builds文件夹在主机上不存在。

#1 楼

奇怪的Docker。我在Dockerfile中更改了WORKDIR,它起作用了:

FROM postgres:9.6

WORKDIR /builds/user/
ADD repo/script.sql /docker-entrypoint-initdb.d/


EDIT
主机系统上不存在/builds文件夹。我认为将其添加到运行程序的配置中会创建一个在容器之间共享的卷容器。但不是。所以我从运行程序配置/etc/gitlab-runner/config.toml中删除了它:

[[runners]]
  name = "My Docker Runner"
  url = "http://host"
  token = "xxxxxxxxxxxxxxxxxxxx"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:latest"
    privileged = false
    disable_cache = false
    volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
  [runners.cache]