我有一个lxd
容器,名为master
. 我发现它的根可以在以下位置找到:
/var/lib/lxd/containers/master/rootfs/home/ubuntu/
所以,我把我的文件夹转移tars
到了这个地址。注意tars
有两个文件。
现在,我知道用户 id 和组 idtars
是root
. 另一方面,容器中每个其他文件的用户 ID 和组 ID 都是166536
.
因此,对于文件夹和文件,我sudo chown 166536 <file/folder name>
更改了用户 ID,并sudo chown :166536 <file/folder name>
更改了组 ID。
有一次,我这样做了,我希望tars
可以从 container 访问master
,但这并没有发生。谁能告诉我我错过了什么?
这是我在reddit上找到的一种方法:
是的,这就是答案,使用非特权容器运行您无法看到 LXD 主机上的权限,因此它显示为“Nobody:Nobody”。在某种程度上是愚蠢的,因为您可以将文件夹安装到容器中并查看其中的文件..
供将来参考,对于遇到此问题的任何人,这是我所做的步骤(它可能不是正确的,但它有效)
sudo mkdir /tmp/share adduser subsonic --shell=/bin/false --no-create-home --system --group --uid 6000 (this is a "service account") sudo chown -R subsonic: /tmp/share lxc exec Test -- /bin/bash mkdir /mnt/share adduser subsonic --shell=/bin/false --no-create-home --system --group --uid 6000 (important that the uid is the same) exit lxc stop Test lxc config edit Test (add the line security.privileged: "true" right bellow config: save and exit) lxc start Test lxc config device add MyMusic MyLibrary disk source=/tmp/share path=/mnt/share lxc exec Test -- /bin/bash ls /mnt/share/ (note that the subsonic user is there) exit
很遗憾我找不到将用户映射到非特权容器内的方法。如果有人知道让我知道。
基本上,为主机和容器创建一个通用用户。有什么比这种方法更好的吗?