Start container from container dir

Hello all,

I have a system which consist of 2 hosts and shared storage between these hosts.
I used bind mount to mount directory from shared storage to /var/lib/lxd/containers/.
When I create container both hosts can see container file system.

Is there any way to launch container on 1 host then stop and after using container file system (/var/lib/lxd/containers/) from shared storage start the same container on another host
without downloading the image.

Thanks.

In theory lxd import <container name> should let you do that, re-creating the needed DB records on the other host based on the content of the backup.yaml for the container.

You should use LXD 2.21 or higher if you do that though.

Now I’m using zfs loop file for storing the containers. Two hosts have access to this file. On both systems lxd uses this file as a zfs pool storage. The problem is when I start container on one host the other host don’t see changes in zfs pool and I can’t import container.
How can I get in sync changes in zfs pool (made by lxd) between two hosts?

Thanks.

Ouch, DO NOT DO THAT. ZFS isn’t a clustered filesystem, sharing its underlying block device between multiple machines and having the zpool mounted on multiple machines is very much not supported and will almost certainly lead to data corruption.

Only clustered filesystems are safe to mount on multiple machines at the same time but there are very few of those and they usually come with a lot of very complex infrastructure to get them working.

You should immediadtely unload the zpool from your second machine then run a full scrub and check of the zpool on the first to make sure that it’s still consistent.

My goal is to have containers shared between hosts. With using Dir as a backend storage it takes a lot of time to start container because it’s need to copy a lot of small files to shared directory.
In case of ZFS container starts much faster but it turns out a can’t share this type of storage. What if I’ll use ZFS with share.nfs=on option, will it help?
Is there any other way to share containers between hosts?

Thanks.

Yes, with clustering, which will be available in LXD 3.0 in about a month from now (released in tandem with Ubuntu 18.04 LTS, but also available to all distros thereafter).

See the documentation for that at https://github.com/lxc/lxd/blob/master/doc/clustering.md

I found the way to get in sync one ZFS pool on different hosts using zfs export and zfs import.
I created ZFS pool in storage accessible from two hosts.
Then I initialized lxd with existing ZFS pool and spun up the container on first host.
I stoped the container then I did zfs export on first host.
After I did zfs import on other host. I can see everything lxd created on second host.
How I can import this ZFS pool and container on second host?

Thanks.