Accessing LXC container's filesystem from host

I'm looking for a way to access the container's rootfs from the host. While I could just use the directory that was passed to lxc.rootfs, it doesn't have the mounts that the container has, so there are just empty directories instead of the mounts. Is there a way to get the same file tree as the container root?

Thanks :)


Solution 1:

I use the following method for backup using rsync:

Using the pid of the container's init process, you can get it using

# list all hosts:
lxc-ls -f -Fname,pid

# or get pid of one host:
lxc-ls -f -Fpid mycontainer
PID    
-----
13323

Using this information, you can access the host's rootfs using the /proc filesystem.

cat /proc/13323/root/etc/hostname
# returns: "mycontainer"

Solution 2:

The best solution I was able to find is to apply the same mounts both on the host and inside the container (via lxc.mount[.entry]). Mounts from the host do not transfer to the container as the container is fully isolated from the host's mounts.