【问题标题】:how to build docker image from singularity image如何从奇异图像构建 docker 图像
【发布时间】:2020-02-28 12:26:53
【问题描述】:

我目前正在研究奇异性和 docker。我正在为 MPI 环境运行奇点。

我想利用 MPI 的奇异性优势,但奇异性文件非常大。所以在运行奇点图像之后,我想 将其转换为 docker 镜像,然后保存,这样可以节省磁盘空间。

这可以将奇异图像转换为 docker 图像吗?

【问题讨论】:

    标签: docker containers singularity-container


    【解决方案1】:

    使用 Singularity 容器化 MPI 应用程序并不是很困难,但它的代价是对主机系统的额外要求。

    这意味着您必须为此自定义图像选择正确的图像库。 this example 之类的东西:

    FROM tacc/tacc-ubuntu18-mvapich2.3-psm2:0.0.2
    
    RUN apt-get update && apt-get upgrade -y && apt-get install -y python3-pip
    RUN pip3 install mpi4py
    
    COPY pi-mpi.py /code/pi-mpi.py
    RUN chmod +x /code/pi-mpi.py
    
    ENV PATH "/code:$PATH"
    

    【讨论】:

    • 用奇异性容器化 MPI 应用程序不是我关心的问题。我以前做过。我只是想将奇异图像转换为 docker 图像。
    【解决方案2】:

    一般来说,它是在另一个方向上完成的:基于 Docker 构建一个奇点镜像。如果您打算将其存储为 docker 映像而不是奇异点,那么最好的选择是将其构建为 Docker 并根据需要转换为奇异点。我知道有几个实验室使用这种方法:通过 Dockerfile 构建,推送到 Docker hub 进行存储,直接从 docker hub 镜像构建奇异镜像。

    但是,奇点图像通常比 docker 图像小。另一个答案tacc/tacc-ubuntu18-mvapich2.3-psm2:0.0.2 中提到的基础 docker 镜像是 497MB,但奇点镜像只有 160MB。 ubuntu:latest 是 64.2MB 和 25MB,python:latest 是 933MB 和 303MB。

    【讨论】:

    • 奇点图像通常不会更小。您引用的 docker 图像的大小是未压缩的大小。例如,ubuntu:latest 的压缩大小为 25.9 MB,python 为 341.02 MB。
    • 很高兴看到 docker 可以将图像压缩得更小。虽然这确实使它们在大小上大致相当,但在所有这些情况下,奇点仍然有点小。
    • 是的 docker 使用 gzip 压缩,squashfs 默认使用 gzip 压缩。奇点在引擎盖下使用 squashfs。
    【解决方案3】:

    正如@tsnowlan 在他们的回答中所说,通常工作流程是从 Docker 到 Singularity。但是有一种方法可以从现有的 Singularity 镜像制作 Docker 镜像。这不会利用 Docker 的层缓存功能。

    总体思路是:

    1. 将 Singularity 图像文件系统转储为 squashfs 文件。
    2. 将 squashfs 文件解压到一个目录中。
    3. 创建一个继承自 scratch 的 Dockerfile,复制 Singularity 映像的文件系统,并设置环境变量和其他内容。
    4. 构建 Docker 映像。

    这里是 bash,在 alpine:latest 上演示:

    singularity pull docker://alpine:latest
    # Find out which SIF ID to use (look for Squashfs)
    singularity sif list alpine_latest.sif
    # Get the environment variables defined in the Singularity image.
    singularity sif dump 2 alpine_latest.sif
    singularity sif dump 3 alpine_latest.sif > data.squash
    unsquashfs -dest data data.squash
    # See the Dockerfile definition below
    docker build --tag alpine:latest .
    

    Dockerfile 的内容:

    FROM scratch
    COPY data /
    ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    CMD ["/bin/ash"]
    

    有关 Singularity 和 Docker 的更多信息,我建议查看 Singularity's documentation on the topic

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 1970-01-01
      • 2021-02-04
      • 2016-12-22
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多