<p>Weird Docker. I changed the <em>WORKDIR</em> in the <em>Dockerfile</em> and it worked:</p>

<pre><code>FROM postgres:9.6

WORKDIR /builds/user/
ADD repo/script.sql /docker-entrypoint-initdb.d/
</code></pre>

<p><strong>EDIT</strong>
The <code>/builds</code> 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, <em>/etc/gitlab-runner/config.toml</em>:</p>

<pre><code>[[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]
</code></pre>

CC BY-SA 3.0
2017-09-25T13:32:54.053Z
2017-09-25T14:01:58.117Z
2017-09-25T14:01:58.117Z
Zoran
<p>I am trying to build a docker image using Gitlab Docker runner. </p>

<p>For this I have configured the runner with a shared volume in <em>/etc/gitlab-runner/config.toml</em> called <em>/builds</em>:</p>

<pre><code>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]
</code></pre>

<p>I created a <em>.gitlab-ci.yml</em> in my repo which loosely looks like this:</p>

<pre><code>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
</code></pre>

<p>I have also created a <em>Dockerfile</em> in the repo which looks like this:</p>

<pre><code>FROM postgres:9.6

ADD /builds/user/repo/script.sql /docker-entrypoint-initdb.d/
</code></pre>

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

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

<p>So I imagine that the <em>/builds</em> 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 <em>docker build</em> command and then to the newly created container. </p>

CC BY-SA 3.0
2017-09-22T14:08:19.613Z
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
CC BY-SA 3.0
2017-09-25T13:57:23.430Z
The files are there. Actually the `/builds` folder does not exists on the host.
Zoran
<docker><continuous-integration><gitlab>
Building a Docker container using Gitlab CI Docker runner
Zoran
# Building a Docker container using Gitlab CI Docker runner

(Asked by: username_0 on 2017-09-22)

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.

**Tags:** docker, continuous-integration, gitlab

> **Comments:**
> **username_1**: 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.  
> **username_0**: The files are there. Actually the `/builds` folder does not exists on the host.  

---

## 1 answers

### Answer by username_0 on 2017-09-25. Score: 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]


---

