Cannot figure out how to mount volume

Hi

trying to mount a volume int one of my build steps…

here I simplified a bit the case:

I have the following files structure:

structure

Dockerfile:

FROM python:3.6.6

ENV PYTHONUNBUFFERED 1
ADD main.py /main.py
CMD ["python", "main.py"]

.drone.yml

pipeline:
  build:
    image: docker
    commands:
      - docker build -t sample .
      - ls /drone/src/data
      - docker run -v /drone/src/data:/data sample ls -l /data
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

the data folder does not getting mounted to the container…
ls /drone/src/data - works

ls in container - does not work

here is a an output of the build:

...
Successfully built 89f30c160feb
Successfully tagged sample:latest
+ ls /drone/src/data
file.txt
+ docker run -v /drone/src/data:/data sample ls -l /data
total 0

this is expected.

docker is running on the host machine (you have linked the host machine daemon) and therefore you are instructing docker to mount /drone/src on the host machine. /drone/src is a path inside a docker container, which is why the mount does not work.

thanks you for quick reply

any suggestions to work this around ?

basically I have a data folder with lot of test data that I do not want to be part of the docker image, but want to be able to test my container using this test data

@vitalik have you managed to resolve this? I am trying to persist mysql data on the host server and can’t figure out how to setup the volumes.

I think you need to pass volume as well to a pipeline step:

pipeline:
  build:
    image: docker
    commands:
      - docker build -t sample .
      - ls /drone/src/data
      - docker run -v /drone/src/data:/data sample ls -l /data
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /drone/src/data:/drone/src/data   # !!!!  <<<<< !!!!!!!
1 Like

I’m trying the above examples with the new pipeline syntax as follow:

kind: pipeline
type: docker
name: default

steps:
- name: testing
  image: docker
  commands:
  - docker ps
  volumes:
  - /var/run/docker.sock:/var/run/docker.sock

But a drone exec (version 1.2.1) just return:

2020/02/14 16:50:58 yaml: unmarshal errors:
  line 11: cannot unmarshal !!str `/var/ru...` into yaml.VolumeMount

@trepmag the examples in this thread are outdated and use syntax from Drone 0.8. The syntax changed in Drone version 1.0 and higher. You can see the syntax for mounting volumes in 1.0 at https://docs.drone.io/pipeline/docker/syntax/volumes/host/

We also provide a working example of mounting the docker socket in our docs:
https://docs.drone.io/pipeline/docker/examples/services/docker/

1 Like

Having the same issue: a step of a pipeline that execute a docker run trying to mounting the /drone/src :
docker run -e RUN_LOCAL=true -v /drone/src:/tmp/lint github/super-linter:slim-v4

but the content inside is empty. The interesting step definition is :

volumes:

  • name: dockersock
    host:
    path: /var/run/docker.sock

    name: license
    image: docker:dind
    pull: always
    volumes:

    • name: dockersock
      path: /var/run/docker.sock

The result is that inside the container the /tmp/lint is empty.
Any suggestions?
Thank you in advance!

@lzecca78 see my previous comment:

http://discuss.harness.io/t/cannot-figure-out-how-to-mount-volume/3808/2?u=bradrydzewski

If you want to interact directly with the docker daemon and create containers on the host, perhaps a container-based pipeline is not the best option for you. Have you considered using something like the exec runner which runs directly on the host and does not run inside containers, allowing you better access to docker? [1][2]

[1] https://docs.drone.io/pipeline/exec/overview/
[2] https://docs.drone.io/runner/exec/overview/

1 Like