我目前正在使用Singularity和Docker进行工作。我正在为MPI环境运行Singularity。
我希望利用Singularity的优势来进行MPI,但是Singularity文件非常大。因此,在运行Singularity镜像后,我想将其转换为Docker镜像,然后保存它,这将节省磁盘空间。
是否可以将Singularity镜像转换为Docker镜像?
我目前正在使用Singularity和Docker进行工作。我正在为MPI环境运行Singularity。
我希望利用Singularity的优势来进行MPI,但是Singularity文件非常大。因此,在运行Singularity镜像后,我想将其转换为Docker镜像,然后保存它,这将节省磁盘空间。
是否可以将Singularity镜像转换为Docker镜像?
正如@tsnowlan在他们的回答中所说,通常的工作流程是从Docker到Singularity。但是有一种方法可以从现有的Singularity镜像创建Docker镜像。这不会利用Docker的层缓存功能。
一般的想法是:
这是在alpine:latest
上演示的bash代码:
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 .
FROM scratch
COPY data /
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CMD ["/bin/ash"]
一般来说,是反过来做的:基于Docker构建一个Singularity镜像。如果您计划将其存储为Docker镜像而不是Singularity,则最好将其构建为Docker并根据需要转换为Singularity。我知道有几个实验室使用这种方法:通过Dockerfile构建,将其推送到Docker Hub进行存储,然后直接从Docker Hub镜像构建Singularity镜像。
但是,Singularity镜像通常比Docker镜像小。在其他答案中提到的基本Docker镜像tacc/tacc-ubuntu18-mvapich2.3-psm2:0.0.2
大小为497MB,而Singularity镜像仅为160MB。ubuntu:latest
大小为64.2MB vs 25MB,python:latest
大小为933MB vs 303MB。
使用Singularity将MPI应用程序容器化并不是非常困难,但这需要主机系统具备额外的要求。
这意味着你必须为自定义镜像选择正确的基础镜像。 例如:这个例子:
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"
ubuntu:latest
的压缩大小为25.9 MB,而Python则为341.02 MB。 - jkr