是否可以在我不是管理员的系统上的容器内构建容器?

Is it possible to build containers from within a container on a system where I am not admin?

我想在本地构建 singularity recpies,而不是依赖 Singularity hub 并将我有限的每日构建配额浪费在修复愚蠢的语法错误上。但是,我不是机器上的管理员,我将 运行 容器。我想在 Singularity hub 上构建一个容器,我是其中的管理员并且可以构建其他容器。但是,我尝试构建一个可以使用 sudosu 的容器,这让我觉得这是不可能的。有什么方法可以设置一个容器,我可以在其中构建容器,如果可以,我当前的方法有什么问题?

我的配方中有以下代码来创建一个用户 "ubuntu",密码 "ubuntu" 并且是 "sudo" 组的成员:

Bootstrap:docker
From:ubuntu:xenial
#...some other stuff that doesn't matter here...
%post
apt-get update
apt-get install -y sudo

useradd ubuntu
echo "ubuntu:ubuntu" | chpasswd
usermod -aG sudo ubuntu

配方在 Singularity 中心上成功构建。但是,我不能在容器中使用 sudosu

$singularity build --sandbox xenial shub://path/to/my/container:xenial
<container builds with some warnings about my account being non-root>
$singularity shell xenial
Singularity: Invoking an interactive shell within container...

Singularity xenial$ su ubuntu
Password:            #I type "ubuntu"
su: Authentication failure
Singularity xenial$ sudo whoami
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
Singularity xenial$ls -l /usr/bin/sudo
-rwxr-xr-x. 1 hbraunDSP dip 136808 Jun 10 22:53 /usr/bin/sudo

这是否太不安全以至于不可能?如果可能的话,我该如何制作一个我可以用来构建容器的容器?

Singularity 默认挂载 /etc/passwd,因此容器内可用的用户与主机上的用户相同。因此,就图像而言,您添加的新 ubuntu 用户在您被炮击时并不存在。

如果您想在 运行 构建奇点图像的同时在另一个图像中构建奇点图像,至少您需要 sudo singularity shell ... 以便保留您的 sudo / root 权限。

或者,如果您使用 --privileged 选项,您可以从 Docker 容器内部构建奇点图像。