Sharing directories with LXC containers

First, you need to make sure the UID of the root user in the container (if you're using root) maps to the UID of the owner of the shared directory:

johannes@host: ls -ln <source_dir>
drwsrwsrwt 7 1000 1000 4096 Oct 9 11:33 .

In this case, it's 1000

Then, configure the container to use that same UID for the root user

johannes@host: sudo lxc config set <container> raw.idmap "both 1000 0"

You'll need to restart the container for these changes to take effect

johannes@host: sudo lxc restart <container>

Then, add the folder as a device to the container

johannes@host: sudo lxc config device add dev <container> disk source=/<source_dir> path=/shared/<some_folder_name>

Double check that the permissions are set correctly in the mounted directory

root@dev: ls -la /shared
total 8
drwxr-xr-x 1 root root 54 Oct 9 15:31 .
drwxr-xr-x 1 root root 256 Oct 9 15:30 ..
drwsrwsrwt 9 root root 4096 Oct 9 15:36 pass-import-1pux

That looks good! You're now able to read/write that folder from inside the container.