Easy way to transfer files between host and LXC container on LVM

Revised answer: LXC containers share the same kernel as the host, so any filesystem they mount should be accessible from outside.

If you do a cat /proc/mounts on the host, can you see the container filesystems?

If you see a line like /dev/mapper/... /var/lib/lxc/o1/rootfs ext4 ... then you should be able to access /var/lib/lxc/o1/rootfs from the host, without any further commands.


I know that this is an old question, but for someone ending up here while searching for how to copy files between host and container, this might help.

To pull a file 'my-file' from the container 'container-name' to the current folder, use:

lxc file pull container-name/any-path/my-file .

To push 'my-file', use:

lxc file push my-file container-name/any-path/

To push a folder 'my-dir' recursive, use:

lxc file push -r my-dir container-name/any-path/

A better, somehow built-in way, of transfering data from host to lxc-container is line #4 in below code:

1 $ mkdir /tmp/transferDir
2 $ cp <some files> /tmp/transferDir/<some files>
3 $ cd /tmp
4 $ tar -C transferDir -c . | lxc-attach -n <container_name> -- /bin/sh -c "tar -C /tmp/ -vx; chmod 1777 /tmp;"
5 $ rm -r /transferDir

The chmod 1777 /tmp is important, otherwise after copying rights on that folder (the containers /tmp) are changed and you would run into problems like this frequent one about xyz-sql server not being able to restart and others.