This is an easy task in the case of containers that share the same filesystem but I'm not sure what would be the proper approach for containers that use LVM disks.

I know I could use rsync or scp but I would like to know if it is possible to do this without setting up ssh/ftp/http servers. Additionally, it would be nice to be able to transfer the files without modifying container's config since it would require a container restart. It would be a good idea to avoid persistent mounted shared folders since these might bring a potential security risk (easy mount/umount option should be available).

An option that popped up in my mind would be to use a WebDAV server on the host and mount it in the container but I haven't yet analyzed it and I'm not sure about the performance penalty that it might bring. Other option that I though of is to mount the LVM partition on the host but I'm not sure whether this is safe.


In my configuration I'm creating the containers using the following command:

lxc-create -t ubuntu -n "${NAME}" -B lvm --vgname lxc-vg --fssize "${SIZE}"

I'm using the default configuration except for the autostart feature which is achieved by adding the following lines to /var/lib/lxc/${NAME}/config file:

lxc.start.auto = 1
lxc.start.delay = 0
  • 1
    How are you starting the containers? How are they configured? Give us some details of your local configuration so that we can give you some suggestions.
    – larsks
    Commented Mar 14, 2015 at 16:56
  • @larsks I updated the question although I don't think the configuration I'm using is very relevant, the only relevant part is that I'm using LVM.
    – s3v3n
    Commented Mar 14, 2015 at 18:42
  • So much attitude...
    – ewwhite
    Commented Mar 18, 2015 at 11:48

3 Answers 3


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.

  • 1. Using LVM with ex4. 2. Machines are running (I said that it would be nice to setup something that doesn't require a reboot)... Therefore you're stating the obvious... Thanks for the answer anyway
    – s3v3n
    Commented Mar 18, 2015 at 11:26
  • 1
    Wait, can you see the container filesystems if you do a cat /proc/mounts from the host? Can you paste one line of output from it?
    – Tobia
    Commented Mar 18, 2015 at 11:49
  • Here it is: pastebin.com/raw.php?i=BUcyFuyt , can't see anything like that :(
    – s3v3n
    Commented Mar 18, 2015 at 12:43
  • 1
    OK, I found something very interesting: /proc/$C_PID/root appears to be a symlink to /, but it's actually the root folder of the container, even if it doesn't show up in mounts. Let's dig further this way!
    – s3v3n
    Commented Mar 18, 2015 at 15:00
  • 1
    Found here: stgraber.org/2013/12/21/lxc-1-0-advanced-container-usage
    – s3v3n
    Commented Mar 18, 2015 at 15:01

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/
  • 3
    This works in lxd (2.0). The question was about lxc (v1, the old version).
    – s3v3n
    Commented Jun 23, 2018 at 21:31

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .