Unable to write to json file if script is symbolic link to host mount

I have a node.js application that works great inside a container but when I try to use the host as a place to store and work on the code it will no-longer update files that it needs to write.

I am trying to:

  • Use my host system to put my main scripts that I edit using a GUI editor :heavy_check_mark:
  • mount the host inside the container :heavy_check_mark:
  • link to the scripts in the host :heavy_check_mark:
  • launch testing.js which will run the code that has been linked :heavy_check_mark:
  • update the text in a db .json file (a simple write file command) ✘ (not working)

I made the container privileged and did the mount:

lxc config device add c1 host disk source=/home path=/home/host readonly=false
lxc config set c1 security.privileged true
lxc restart c1

Inside the container’s /home directory:

drwxrwxrwx 13 root     root       14 Jul 26 14:50 db
drwxr-xr-x  9     1001     1001 4096 Jul 31 13:52 host
lrwxrwxrwx  1 root     root       28 Jul 25 16:11 private_js -> /home/host/private_js
-rwxrwxrwx    root     root      112 Jul 25 16:10 testing.js

inside the /home/db directory:

-rwxrwxrwx 1 root root  657 May 19 12:42  temp.json

inside /home/host/private_js mounted directory:

-rwxr-xr-x 1 root root 28107 Jul 31 15:34 driver.js

What did I do wrong, should I have used propagation=shared when mounting??

The container is privileged but, It is as if the host is not privileged so any script that the host is hosting cannot be used to write to the json file inside the container even though the scripts are being launched from the container.

You shouldn’t need security. privileged here, if not needed for your code id remove that.

There is a few ways to-do this, personally I quite like shiftfs if the container is local and not remote (In which case you can use the sshfs/sftp they recently introduced if remote)

Here’s some information on getting a shiftfs disk setup (despite doing it numerous times I cant remember the exact commands you need)

1 Like

tried all instructions even followed this: Use shiftfs in LXD · toby63/shiftfs-dkms Wiki · GitHub

still unable to write files if the script on the host is a symbolic link to the container