Switch container, keep data volume


I was wondering if this scenario would be possible with LXD and ZFS (dataset)

  • Create container cont-A (version 001)
  • Create a volume data voldata-A
  • Attach volume voldata-A to cont-A (mount point inside container /voldata )

As I understood, LXD will take care of UID/GID mapping . ( Mounting ZFS datasets to containers )
But once I have this setup working, with datas, can I do this :

  • Stop container cont-A
  • Detach volume voldata-A from cont-A (not sure if that’s possible with “lxc storage xxx”
  • Delete container cont-A
  • Clone container TEMPLATE-v002 to container cont-A (version 002)
  • Attach volume voldata-A to cont-A (mount point inside container /voldata )
  • Start container

This way, I could manage my images, and just “switch” the container core system without touching my datas

Will LXD allow me this scenario without any conflicts on UID/GID inside the container ?

Thanks !

Yep, that should work fine.

If your containers each have their own uid/gid map (security.idmap.isolated), then a custom volume may only be attached to one container at a time. But even in that case, you’re fine since you’ll detach it from a container and attach it to another.

LXD does keep track of what the attached container’s map was for the storage volume and will take care of remapping from one map to the other when moving the volume between containers.

Perfect, good to know, thanks @stgraber