1

Working in Jenkinsx build container ... I'm trying to mount a volume while in docker container. The directory get's mounted, however, the files that exist on source ( host ) directory are not present in the container.

In this case, the host is a docker container as well, so basically I'm running docker-compose from docker container.

Does anyone experienced this issue and has a solution?

Here are the results :

bash-4.2# pwd
/home/jenkins
bash-4.2# ls -l datadir/
total 4
-rw-r--r-- 1 root root 4 May 15 20:06 foo.txt
bash-4.2# cat docker-compose.yml
version: '2.3'
services:
  testing-wiremock:
    image: rodolpheche/wiremock
    volumes:
      - ./datadir:/home/wiremock
bash-4.2# df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay          95G   24G   71G  25% /
tmpfs           7.4G     0  7.4G   0% /dev
tmpfs           7.4G     0  7.4G   0% /sys/fs/cgroup
/dev/sda1        95G   24G   71G  25% /etc/hosts
tmpfs           7.4G  4.0K  7.4G   1% /root/.m2
shm              64M     0   64M   0% /dev/shm
tmpfs           7.4G  4.0K  7.4G   1% /home/jenkins/.docker
tmpfs           7.4G  1.9M  7.4G   1% /run/docker.sock
tmpfs           7.4G     0  7.4G   0% /home/jenkins/.gnupg
tmpfs           7.4G   12K  7.4G   1% /run/secrets/kubernetes.io/serviceaccount
bash-4.2# docker-compose up -d
Creating network "jenkins_default" with the default driver
Creating jenkins_testing-wiremock_1 ... done
bash-4.2# docker ps |grep wiremock
6293dee408aa        rodolpheche/wiremock                                  "/docker-entrypoint.…"   26 seconds ago      Up 25 seconds               8080/tcp, 8443/tcp                 jenkins_testing-wiremock_1
8db3b729c5d2        rodolpheche/wiremock                                  "/docker-entrypoint.…"   21 minutes ago      Up 21 minutes (unhealthy)   8080/tcp, 8443/tcp                 zendeskintegration_rest_1
bd52fb96036d        rodolpheche/wiremock                                  "/docker-entrypoint.…"   21 minutes ago      Up 21 minutes (unhealthy)   8080/tcp, 8443/tcp                 zendeskintegration_zendesk_1
bash-4.2# docker exec -it 6293dee408aa bash
root@6293dee408aa:/home/wiremock# ls -ltr
total 8
drwxr-xr-x 2 root root 4096 May 15 20:06 mappings
drwxr-xr-x 2 root root 4096 May 15 20:06 __files 
Nerses
  • 709
  • 2
  • 9
  • 15
  • you have one image runing in 3 containers. are you sure you analysed the latest created one? – olidem May 15 '19 at 20:44
  • @OlliD-Metz If you look at "root@6293dee408aa" you can see that he did analyse the correct one. – Mihai May 16 '19 at 05:59
  • but what if the docker-compose up created the container 8db3b...? The 6293... could just be an old one – olidem May 16 '19 at 06:01
  • @Nerses In your Dockerfile you declare /home/wiremock as a volume and you even place a script in there. This means that you cannot mount a host directory to it anymore to bring in more files (it does not merge them as you would hope). You can mount your directory to a different path and then it will work. And in your docker-entrypoint.sh you can copy thos files to your /home/wiremock directory. But this way you would have to restart always when something changes... – Mihai May 16 '19 at 06:01
  • @OlliD-Metz it says created 26 seconds ago for container 6293dee408aa. Maybe you can scroll to the right? – Mihai May 16 '19 at 06:03
  • @Nerses The fact that your output still shows 3 containers is also a bad sign. You should clean it and make sure nothing is running. Why I am saying it is because "docker-compose down" usually cleans up also created mount volumes. From your situation I can also assume that you might have a stale volume that is causing problems. Run "docker volume ls" and make sure that shows no entries before doing your docker-compose up again. You can remove volumes with "docker volume prune" – Mihai May 16 '19 at 06:06
  • @Mihai yeah, I did not see this, you are right. I am in line with you about the two left over unhealthy containers. – olidem May 16 '19 at 06:48
  • @Mihai thank you! I've tried mounting on /mnt/datadir but have the same results. – Nerses May 16 '19 at 13:27
  • I think I found the answer, but first a question: you say you run container in container. Do you mount the docker socket in the parent container to have access to the docker service? – Mihai May 16 '19 at 14:03
  • I'm using Jenkinsx for CI/CD. So first Jenkins already runs in a container then the build environment is a container within Jenkins container and then the tests try to launch more containers to run tests against. I don't mount the parent ( build env ) in any of the containers. – Nerses May 20 '19 at 01:49

1 Answers1

1

I could reproduce the issue by running this on a MacOS system:

First open a shell in a container that already has docker-compose installed:

docker run --rm -v $(pwd):/work -v /var/run/docker.sock:/var/run/docker.sock --workdir /work -ti tmaier/docker-compose sh

I map the current folder so that I can work with my current project as if it were on my host.

And then inside the container:

docker-compose run testing-wiremock ls -lart

Now change the docker-compose.yml to the following:

version: '2.3'
services:
  testing-wiremock:
    image: rodolpheche/wiremock
    volumes:
      - /tmp:/home/wiremock/

and run again:

docker-compose run testing-wiremock ls -lart

This will show you the contents of the /tmp directory on the host (where the docker socket actually runs). To test you can even create a folder and a file in the /tmp and run the "docker-compose run" again. You will see the new files.

Moral of the story: If the mounted folder corresponds to an existing folder on the host where the docker daemon is actually running, then the mapping will actually work.

host -> container -> container (mounts here refer to paths on the host)

In your specific case the folder is mounted empty because the mounted path (check it by running docker-compose config) is not present on the host (host = the host running your Jenkins container, not the Jenkins container itself).

Mihai
  • 9,526
  • 2
  • 18
  • 40