You can assign additional devices to the container, and these can be host-accessible folders.
$ lxc config ## display help
...
lxc config device add [<remote>:]<container> <device> <type> [key=value...]
Add a device to a container.
...
Note that <device>
is just an arbitrary name that you assign, which will be used as an ID for subsequent device management.
For example, to mount the host folder "./host" as "/mnt/host" in the container...
lxc config device add mycontainer vartest disk source=$(pwd)/host path=/mnt/host
There remains one problem -- if you want this folder to be writable by both the host and the container, the ownership and permissions need to be configured accordingly. This is complicated by the default mode of LXD which virtualizes the numeric ranges for user and group id
values. There is an easy solution, however: bypass this virtualization by configuring the container to run with host-equivalent privileges...
lxc config set <container> security.privileged true
The full host-security implications of this approach are unclear to me at this time, but would seem to be somewhat "contained" by the virtualization. The practical risk depends on how and why you will be using the container. See technical notes at https://insights.ubuntu.com/2017/06/15/custom-user-mappings-in-lxd-containers
Further note that this approach probably works best if you normally operate in the container as a non-root user, such as if you attach with...
lxc exec zesty -- su --login ubuntu
lxc config device add confexample sharedtmp disk path=/tmp source=/tmp/shared
. But looking at the directory on the container the owner and group for the files in there are set to 'nobody' and 'nogroup' and the mount is read only.lxc file
to transfer files between host and container, usingpush
andpull
.