简体   繁体   English

如何从奇异图像构建 docker 图像

[英]how to build docker image from singularity image

I am currently working on singularity and docker.我目前正在研究奇点和 docker。 I am running singularity for MPI environment.我正在为 MPI 环境运行奇点。

I want to use advantages of singularity for MPI but singularity files are very large.我想将奇点的优势用于 MPI,但奇点文件非常大。 So after running the singularity image I want to convert it to docker image and then save it which will save the disk space.因此,在运行奇异图像后,我想将其转换为 docker 图像,然后保存它,这将节省磁盘空间。

Is this possible to convert singularity image into docker image?这是否可以将奇异图像转换为 docker 图像?

Containerizing MPI applications is not terribly difficult with Singularity, but it comes at the cost of additional requirements for the host system.使用 Singularity 将 MPI 应用程序容器化并不是非常困难,但它是以对主机系统提出额外要求为代价的。

This means you have to choose the right image base for this custom image.这意味着您必须为此自定义图像选择正确的图像库。 Something like 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"

Generally speaking, it's done in the other direction: building a singularity image based on Docker.一般来说,它是在另一个方向上完成的:基于 Docker 构建奇异图像。 If you plan on storing it as a docker image rather than singularity, your best bet would be to build it as Docker and convert to singularity as needed.如果您打算将其存储为 docker 镜像而不是奇点,那么最好的办法是将其构建为 Docker 并根据需要转换为奇点。 I know of several labs using this method: build via Dockerfile, push to Docker hub for storage, build singularity image directly from docker hub image.我知道有几个实验室使用这种方法:通过 Dockerfile 构建,推送到 Docker hub 进行存储,直接从 docker hub 镜像构建奇异镜像。

However, singularity images are usually smaller than docker images.但是,奇异点图像通常比 docker 图像小。 The base docker image mentioned in the other answer, tacc/tacc-ubuntu18-mvapich2.3-psm2:0.0.2 , is 497MB but the singularity image is only 160MB.另一个答案中提到的基本tacc/tacc-ubuntu18-mvapich2.3-psm2:0.0.2是 497MB,但奇点映像只有 160MB。 ubuntu:latest is 64.2MB vs 25MB, python:latest is 933MB vs 303MB. ubuntu:latest是 64.2MB vs 25MB, python:latest是 933MB vs 303MB。

As @tsnowlan said in their answer, typically the workflow is from Docker to Singularity.正如@tsnowlan 在他们的回答中所说,通常工作流程是从 Docker 到 Singularity。 But there is a way to make a Docker image from an existing Singularity image.但是有一种方法可以从现有的 Singularity 映像制作 Docker 映像。 This would not make use of Docker's layer caching features.这不会利用 Docker 的层缓存功能。

The general idea is to:总体思路是:

  1. Dump the Singularity image filesystem as a squashfs file.将 Singularity 图像文件系统转储为 squashfs 文件。
  2. Extract the squashfs file into a directory.将 squashfs 文件解压到一个目录中。
  3. Create a Dockerfile that inherits from scratch , copies over the Singularity image's filesystem, and sets environment variables and other things.创建一个从头开始继承的 Dockerfile,复制 Singularity 映像的文件系统,并设置环境变量和其他内容。
  4. Build the Docker image.构建 Docker 镜像。

Here it is in bash, demonstrated on alpine:latest :这是在 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 .

Contents of Dockerfile: Dockerfile 的内容:

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

For more information on Singularity and Docker, I recommend looking at Singularity's documentation on the topic .有关 Singularity 和 Docker 的更多信息,我建议您查看Singularity 有关主题的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM