This episode teaches sharing data between host and container via lxc.mount.entry bind-mounts, read-only mount options, sharing data and configuration directories, and device access from inside containers.

Containers have their own filesystem (rootfs), but sometimes they need data from the host: a project directory under development, a shared data volume between containers, or config managed from outside. In episode 11 we use bind-mounts — mounting host directories into the container — via lxc.mount.entry. This is the feature that makes LXC feel like "a real machine that can share disks".
A bind mount makes a host directory "stick" to another location inside the container's filesystem, without copying data. Both sides see the same files — a change on one side is immediately visible on the other. Think of it like a hard link for an entire directory: one data, two access doors.
Its strengths: no data duplication, no synchronization to maintain. Its drawback: you have to be careful with permissions and with what you share.
Bind mounts are declared in the container config:
# Format: <source> <mountpoint in container> <fstype> <options> <dump> <fsck>
lxc.mount.entry = /srv/data c1/srv/data none bind 0 0
lxc.mount.entry = /etc/ssl/certs c1/etc/ssl/certs none bind,ro 0 0Let's break down the format (similar to the columns in /etc/fstab):
source — the host path (/srv/data).mountpoint — the destination inside the container. The format can be c1/srv/data (relative to the rootfs) or ../.. for rootfs paths.fstype — none for bind.options — bind for a regular mount, bind,ro for read-only.dump and fsck — 0 columns (ignored).After editing the config, restart the container so the mount takes effect:
lxc-stop -n c1
lxc-start -n c1Verify from inside the container:
lxc-attach -n c1 -- mount | grep srv
lxc-attach -n c1 -- ls /srv/dataTip
Use the bind,ro option for anything the container shouldn't modify — e.g. config, binaries, or reference data. A read-only mount protects against accidental damage and against interference from hijacked processes inside the container.
The most common example: sharing a data directory between containers, or keeping data on the host disk for easy backup.
lxc.mount.entry = /srv/nginx-html c1/var/www/html none bind 0 0
lxc.mount.entry = /srv/uploads c1/var/www/uploads none bind 0 0Two containers (e.g. web and worker) can share the same /srv/uploads — data is written once, and both read the same files.
Share config managed from the host, or binaries/tooling so they don't need to be installed in every container:
lxc.mount.entry = /srv/conf/nginx.conf c1/etc/nginx/nginx.conf none bind,ro 0 0Host devices can also be mounted into the container. For access to a single device (e.g. a particular USB serial):
lxc.mount.entry = /dev/ttyUSB0 c1/dev/ttyUSB0 none bind,create=file 0 0The create=file option creates the device node in the container if it doesn't exist. For broader device passthrough cases (GPU/USB), we cover that in episode 14.
Warning
Mounting host devices into a container loosens isolation: a rooted, compromised process inside the container can write to that device. Never bind-mount a device without understanding the risk, and combine it with cgroup device limits (episode 14) for truly controlled access.
This is a classic LXC pitfall: bind-mounts follow the host UID, not the container UID. Files in /srv/data owned by UID 1000 (a host user) will appear owned by UID 1000 inside the container. On an unprivileged container, container UIDs are mapped — e.g. container UID 0 = host UID 100000 — so permissions that match on the host won't necessarily match inside the container.
Practical solutions:
setgid.If the mountpoint directory inside the container doesn't exist, the mount fails. Create it first:
lxc-attach -n c1 -- mkdir -p /srv/dataIf the bind mount isn't visible after a restart, check the config syntax and the container log:
cat /var/lib/lxc/c1/log/lxc.log | tail -30Key takeaways:
lxc.mount.entry format: source, mountpoint, fstype, options, dump, fsck.bind,ro locks a directory read-only — the safe default for config/reference data.In the next episode 12 we'll cover containers in Proxmox VE — how PVE uses LXC as its CT engine, the fact that PVE 9.2 ships LXC 7.0 LTS, unprivileged CT as the default, and the practices of Docker-in-LXC and nested virtualization.