LXC: How do I mount a folder from the host to the container?

To create the directory automatically in the container, you can also add the create=dir option in the fstab :

/mnt/ssd/solr_data      /var/lib/lxc/Solr4StandAlone/rootfs/data        none   bind,create=dir

Edit : this is specific to LXC. See this thread

Just like we already had "optional", this adds two new LXC-specific mount flags:

  • create=dir (will do a mkdir_p on the path)

  • create=file (will do a mkdir_p on the dirname + a fopen on the path)

This was motivated by some of the needed bind-mounts for the unprivileged containers.


In /var/lib/lxc/Solr4StandAlone/config add a line reading:

lxc.mount.entry = /mnt/ssd/solr_data  /var/lib/lxc/Solr4StandAlone/rootfs/data none bind 0 0

Then lxc-stop stop your container and lxc-start your container again.

That is all that is needed.

ref: reference link


I had to create the /data folder in the local container before the mount would work properly.

I also used this fstab entry:

/mnt/ssd/solr_data      /var/lib/lxc/Solr4StandAlone/rootfs/data        none   bind     0       0

Tags:

Ubuntu

Mount

Lxc