Is there a way to make a file accessible from all the LXC containers? I have a SQLite database that i want to share with all my containers, is this possible?
1 Answers
Easy peasy. Use mount bind.
Heres an example.
First, create a directory to hold the files you want shared on the host machine.
mkdir /var/shared
Next we need to create a directory in the containers which we can mount to. I'm using default locations in Ubuntu and have 2 Containers. One named "test1" and the other named "test2".
mkdir /var/lib/lxc/test1/rootfs/var/shared
mkdir /var/lib/lxc/test2/rootfs/var/shared
mkdir /var/lib/lxc/<lxc container name here>/rootfs/var/shared
The above commands are optional. You can use whatever sub directory in the container. I say "/var/shared".
Next we do:
mount -o bind /var/shared /var/lib/lxc/test1/rootfs/var/shared
mount -o bind /var/shared /var/lib/lxc/test2/rootfs/var/shared
To make this persistent across Host reboots do the following.
# vi /etc/fstab
Add the following
/var/shared /var/lib/lxc/test1/rootfs/var/shared none rw,bind 0 0
/var/shared /var/lib/lxc/test2/rootfs/var/shared none rw,bind 0 0
Once again, replace test1 & test2 with your proper named containers.
Anything placed into the /var/shared directory will be accessible by all containers that have the mount. But since UID and GID's can be different per sub container, you may have to chmod 666 to have things read / write by the necessary users of each container.
Please leave a comment if you need any further explanation or help. -Frank

- 96
- 6