So the error means that container2 has two disk devices that both have the same path value.
You should see that pretty clearly by looking at the current config through lxc config show --expanded container2
sudo mkdir -p /aa/host
lxc profile create aa
lxc profile device add aa aa disk source=/aa/host path=/aa/host readonly=on
lxc profile add container1 aa
lxc profile add container2 aa
To see which containers use this profile, I do this:
lxc profile show aa
config: {}
description: ""
devices:
aa:
path: /aa/host
readonly: "on"
source: /aa/host
type: disk
name: aa
used_by:
- /1.0/instances/container1
- /1.0/instances/container2
If I want the folder to be writeable by the containers, I set the permissions on the host: sudo chown -R 1000000:1000000 /aa/host
Once I have such a profile, I create similar profiles by copying it and editing it:
lxc profile copy aa bb
lxc profile edit bb
I find this easier than looking up the usage of the “lxc [profile] device” command.