5

I am trying to build a docker image using Gitlab Docker runner.

For this I have configured the runner with a shared volume in /etc/gitlab-runner/config.toml called /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]

I created a .gitlab-ci.yml in my repo which loosely looks like this:

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

I have also created a Dockerfile in the repo which looks like this:

FROM postgres:9.6

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

Everything works alright except for the Docker ADD instruction which fails because the /builds/user/repo/script.sql cannot be found:

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

So I imagine that the /builds volume I am trying to share between containers is not working as I am expecting it to ... Could someone help me with this? I would like to be able to share the code which is cloned on the runner container to the docker build command and then to the newly created container.

  • 2
    You should add a ls -alh /builds/user/repo just before the docker build command to ensure the file is there in the container at least, and maybe continue debugging by adding a sleep 60 to check the content of the directory on the host, as you did mount the docker.sock also. – Tensibai Sep 22 '17 at 14:08
  • The files are there. Actually the /builds folder does not exists on the host. – Boo Sep 25 '17 at 13:57
3

Weird Docker. I changed the WORKDIR in the Dockerfile and it worked:

FROM postgres:9.6

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

EDIT The /builds folder does not exist on the host system. I thought that adding it to the runner's config would create a volume container that would be shared between containers. But no. So I removed it from the runner config, /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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.