将Docker的tar文件转换为Singularity镜像?

8
我是一个新手,对Docker和Singularity都不太熟悉。最近我创建了规范的main.c
#include <stdio.h>
#include <stdlib.h>

int main(void){
    printf("Hello Docker World!\n");
    return 0;
}

我静态编译了这段代码,即。

gcc -static -static-libgcc -static-libstdc++ -o hello main.c

我随后构建了 Docker 镜像并成功运行,即:
dockerd &  ## Start Docker daemon
docker build --tag hello .
docker run hello   ## Outputs "Hello Docker World"

然后我保存图像,以便将其导出到第二台计算机(该计算机没有docker,但有singularity),即。

docker save hello > hello.tar

现在在第二台机器上,没有docker但有singularity,我想创建一个singularity映像。Singularity 文档提供了从Docker Hub上的docker映像创建singularity映像的说明,但他们没有提供从docker tar文件转换的说明。
问题:我该如何从我的hello.tar创建一个singularity映像?

为什么不将其发布到DockerHub并使用呢? - Lakshya Garg
3
我有一些代码不想公开。 - irritable_phd_syndrome
然后创建一个本地的Docker注册表,并将镜像推送到本地注册表。在Singularity中使用它。 - Lakshya Garg
1
第二台机器是CentOS 6.9。看起来它不受Docker支持(https://success.docker.com/article/compatibility-matrix)。我之前尝试在这台机器上安装Docker,但无法获得可用版本。 - irritable_phd_syndrome
在这种情况下,您应该在第一台机器上使用Singularity导出,并在另一台机器上导入。 - Lakshya Garg
3个回答

6
  1. 首先,保存你的Docker镜像。

    sudo docker save image_id -o local.tar

  2. 然后以任何你喜欢的方式将镜像拷贝到另一台机器上。

  3. 最后,通过使用docker-archive引导代理程序从local.tar构建 Singularity 镜像。

    singularity build local_tar.sif docker-archive://local.tar

    这里使用了docker-archive引导代理程序。详情请参考此处


1
如果在第三步的机器上没有访问权限,我该如何做呢? - Rylan Schaeffer
我收到了以下错误信息:ERROR: Unknown container build Singularity recipe format: docker-archive://local.tar ABORT: Aborting with RETVAL=255 - eric_kernfeld
@RuolinLiu 我尝试了你提到的在官方Singularity网站上进行转换的方法。但我遇到的问题是,转换后的镜像与原始镜像相比要小得多(大约1/3),这让我相信构建过程跳过了所有包(也许是自定义的包)在原始Docker镜像中。你有什么想法吗? - Omayr
2
尝试这个:singularity build local_tar.sif local.tar,这对我有效。 - Simon

2
Ruolin Liu的答案是我首先推荐尝试的。
另外,你可以尝试使用工具docker2singularity。 docker2singularity本身就是一个Docker镜像,因此很容易安装。 此外,它还支持当前和旧版本的Singularity。
作为如何在你的hello Docker镜像上使用docker2singularity的示例,你可以...
  1. make a directory to write the singularity image file to

    mkdir -p /tmp/test
    
  2. use docker2singularity on the docker image hello and mount /tmp/test as the output directory

    docker run -v /var/run/docker.sock:/var/run/docker.sock \
    -v /tmp/test:/output \
    --privileged -t --rm \
    quay.io/singularity/docker2singularity \
    hello
    
  3. move the created singularity image file from /tmp/test to a host with singularity and run it


0

使用本地注册表容器如下:

# Start a docker registry
$ docker run -d -p 5000:5000 --restart=always --name registry registry:2
# Push local docker container to it
$ docker tag alpine localhost:5000/alpine
$ docker push localhost:5000/alpine
# Create def file for singularity like this..
# (add your modifications)
Bootstrap: docker
Registry: http://localhost:5000
Namespace:
From: alpine:latest
# Build singularity container
$ sudo SINGULARITY_NOHTTPS=1 singularity build alpine.simg def

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接