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.
ls -alh /builds/user/repo
just before thedocker build
command to ensure the file is there in the container at least, and maybe continue debugging by adding asleep 60
to check the content of the directory on the host, as you did mount the docker.sock also./builds
folder does not exists on the host.