-1

I am using this config to mount drive that is read-only to docker image:

volumes:
  - name: drive-c
    hostPath:
      path: /media/sf_C_DRIVE
containers:
  ...
    volumeMounts:
    - name: drive-c
      mountPath: /c

When I try to write (mkdir) to this folder (which is virtual-box read only mounted folder) inside docker image, I get:

mkdir: can't create directory 'somedir': Read-only file system

Which is OK since this is read-only filesystem (C_DRIVE on /c type vboxsf (rw,nodev,relatime))

Is it possible to somehow make this folder writable inside docker container? Changes does not need to be propagated to hostPath. I read something about overlayfs, but I'm not sure how to specify this in Kubernetes yaml.

Bojan Vukasovic
  • 2,054
  • 22
  • 43

1 Answers1

1

You can't do this via Kubernetes volume mounts, as they simply work on volumes. What you need to do is create a writable overlay filesystem on your host machine, then map that into Kubernetes with a different path that is writable.

You want to create something like /mnt/writable_sf_C_drive by mounting your /media/sf_C_DRIVE with an overlay on top of it, then your volume mount in Kubernetes would mount /mnt/writable_sf_C_DRIVE.

There are some instructions here

  • I thought so. The only problem is that I cannot share same overlayed mount between two docker images (since any of those whould see changes of another one). Also, I read that vboxsf is not supported for overlay-ing. – Bojan Vukasovic Aug 02 '18 at 21:34
  • What about you make an initContainer which has that volume mount, and simply copies everything into your pods, then when the real pod runs, it'll have a copy of the data. – Marcin Romaszewicz Aug 02 '18 at 23:33
  • I needed to share whole drives as you see from my question (so talking about 1TB of data...) which makes it infeasible to copy. Also, I needed to see changes immediately. But in some other use-case could be solution... – Bojan Vukasovic Aug 09 '18 at 14:39