Drone

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