[solved] Mounting a volume when using the docker plugin

I am new to Drone.
But thanks to its superpowers and some help from this forum, I have automated most of the docker image building I intended to and am very happy about it.

However, I still stumble on something I do not understand and would need some help with.

Here is what I would like to do:

  1. I am using a private docker registry at 192.168.1.46:5000.
  2. I want to build an image from Alpine
  3. then push the newly built image to the registry

I have already done it several times successfully but would like to improve the process speed by mounting a directory during the build process where installation files are cached.
So, I would like to mount a volume from the host into the image while I am building it.
It is well known there is no MOUNT instruction for dockerfiles, so I tried this (knowing that the initiating git repo is mounted by default at /drone/src/ then at root within the docker image):

  1. in the drone.yml file, I mount the host volume into a subdirectory of /drone/src:
kind: pipeline
type: docker
name: test

steps:
  - name: publish
    image: plugins/docker
    volumes:
      - name: thevol
        path: /drone/src/thevol
    settings:
      repo: 192.168.1.46:5000/vsr-tst
      registry: 192.168.1.46:5000
      auto_tag: false
      insecure: true
      pull: if-not-exists
      tags: drnbld_${DRONE_BUILD_NUMBER}
volumes:
  - name: thevol
    host:
      path: /home/thevol
  1. then in the Dockerfile I check if I can access the volume at root:
# I pull Alpine
FROM alpine/git
# Copying a file that belongs to the initiating git repo > OK
COPY README_GIT.md /somewhere
# Copying a file that is in the volume I tried to mount inside the `/drone/src directory` > NOK
COPY /thevol/README_MOUNT.md /somewhere_else
  1. I cannot copy the file and instead get an error during the build:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
exit status 1
  1. As soon as I remove the volumes: instruction block nested in the publish step in the drone.yml file, everything works fine again.

Thanks for your help.
S.

While writing my question, I figured out that the correct path of the mounted subdirectory would be instead: thevol/ in the image but it did not work either.

I am facing the same issue. No matter what, I cannot build a docker image using volumes with plugins/docker.

See https://docs.drone.io/plugins/popular/docker/#using-volumes

If you attempt to mount a volume into the plugin you will see the below entry in your pipeline logs […] This can be resolved by removing mounted volumes or by configuring the plugin step to run in privileged mode

See also: