0

Am I able to make it so that If I connect a single-file docker volume to a container, and the application makes an attempt to move or remove the file, the system allows it, rather than returning "Permission denied." or "...is a directory."?

e.g.

docker run -it \
    -v $(PWD)/config:/tmp/buildroot/.config \
    rootbuilder \
    make menuconfig

When the make menuconfig attempts to save the .config file, what it is actually doing is:

  1. Storing it in a temporarily file
  2. Deleting the existing .config file (unlink)
  3. Moving the temporary file into place (move)

Because mounting files in docker is using a tmpfs mount, unlinking or moving it is like attempting to perform that operation on a mount - which makes no sense.

To solve this problem, I could:

  • mount the directory as a volume, but that would mean having to store the rest of the application in the volume so it would not be a clean environment every time; or
  • put the config into a subdirectory and convince the application to find the config there - which is messy; or
  • copy the config into place before running the application, and then pipe the result back into the original file - but this would mean also detecting if that file existed, and would get steadily more complex the more files are involved

Is there a better way to solve the problem of a single-file needing to be moved/removed when mounted through a docker volume?

1 Answers1

0

Is the kernel build system intelligent enough to follow symlinks? Some programs do, others don't, but I'm pretty sure that's the only hope you've got -- put all the files into a directory volume mounted somewhere else in the container, and symlink .config to a file in that volume.

womble
  • 96,255
  • 29
  • 175
  • 230
  • I can check, but my guess is it would delete the symlink instead of emptying the file, and then it would place a real file in place of the symlink, so the config would remain unchanged on the host. – tudor -Reinstate Monica- Nov 30 '15 at 05:04
  • It's not hard to handle symlinks in place (just `readlink` the file, and if it points somewhere else, rewrite/rename that file, instead), but just not everything does. Something as well-used as the kernel build system may well have hit this problem before, and someone has already fixed it. – womble Nov 30 '15 at 05:06