工欲善其事必先利其器
Singularity 是一个容器平台,专为科学计算和数据密集型应用设计。最初是由 Gregory Kurtzer 在 2015 年创立的。Gregory Kurtzer 有着深厚的高性能计算背景,并且在开源社区中有着广泛的贡献。他意识到现有的容器解决方案不能很好地满足科学计算社区的需求,特别是在安全和易用性方面。因此,他创建了 Singularity,目标是提供一个既安全又高效的容器解决方案,特别是为了满足科研和企业中对高性能计算需求。其优势如下:
官网:https://sylabs.io/ 文档:https://sylabs.io/docs/ github:https://github.com/sylabs/singularity
题目:Singularity: Scientific containers for mobility of compute 日期:2017年5月11日 期刊:PLOS ONE 作者&单位:Gregory M. Kurtzer && Lawrence Berkeley National Lab DOI:10.1371/journal.pone.0177459
非root用户推荐使用conda 安装。(唯一不足是Conda安装的singularity不是最新版本)
conda create -n singularity singularity=3.8.6 -y
容器是一种在隔离环境中运行应用程序的技术。与传统虚拟机 (VM) 相比,它们具有多项优势,例如 更快的部署时间和可重复性。容器还允许开发人员构建和部署软件,无需担心底层基础设施或操作系统详细信息。在生物信息学分析中,使用Singularity 容器技术具有以下优势:
singularity run library://library/tutorial101/wttr:latest
shell
允许用户以交互的方式进入到一个特定的容器环境中## 进入特定的容器环境
singularity shell library://josue-sylabs/demo/wttr:latest
INFO: Using cached image
Singularity> _
## 查看容器信息
Singularity> cat /etc/os-release
##退出交互
Singularity> exit
pull
下载容器文件inspect
显示容器的元数据信息--runscript
显示容器的runscript(查看特定元数据类型)。Runscript 是容器的默认执行脚本,当使用 singularity run
命令或直接运行容器文件时会执行.sif
是 Singularity Image Format 的缩写,这是 Singularity 的默认容器映像格式,它是一个单一的、不可变的、和可移植的文件格式
##下载容器映像文件
singularity pull wttr.sif library://josue-sylabs/demo/wttr:latest
## `wttr.sif`:指定下载后的容器映像文件的本地文件名。
##查看容器的默认执行脚本
singularity inspect --runscript wttr.sif
##从Docker Hub下载
singularity pull ubuntu.sif docker://ubuntu
##进入交互——显示调用
singularity shell ubuntu.sif
##非显示调用
./ubuntu.sif
主要分为4步
--writable
选项运行 singularity shell
命令来修改沙盒容器。定义文件分为两部分:
singularity run
命令运行容器映像时执行。%runscript
,不同之处在于,%startscript
中的命令会在执行 singularity instance start
命令时运行。singularity test
命令时执行。/.singularity.d/labels.json
添加元数据,标签通过键值对定义,并可以在执行 singularity inspect
命令时显示。singularity run-help
命令显示这些帮助信息。## 需管理员权限
sudo singularity build --sandbox sandbox/ docker://ubuntu:22.04
sudo singularity shell --writable sandbox/
大部分情况下我们是没有管理员权限,那么我们可以使用以下命令
fakeroot
允许用户在容器及其请求的命名空间内拥有与 root 用户几乎相同的管理权限。这意味着用户可以执行通常需要 root 权限的操作,而不需要实际的 root 权限。通过 fakeroot
用户创建的所有文件或目录,在容器内部归 root 所有,在容器外部则归创建它们的用户和组所有。
--fakeroot
选项只能与以下几个命令一起使用:
shell
:在容器内启动一个 shell。exec
:在容器内执行一个指定的命令。run
:运行容器的默认动作或指定的命令。instance start
:启动一个容器实例。build
:构建一个 SIF 容器映像。非root用户创建一个容器映像
## 新建一个testfiel
echo "This is a test file." > testfile
##创建定义文件
vim test.def
##定义文件写入以下内容
bootstrap: docker
from: almalinux:9
%files
testfile
%post
dnf install -y epel-release
dnf install -y figlet
%runscript
figlet < testfile
## 创建容器映像
singularity build --fakeroot test.sif test.def
## 运行
singularity run test.sif
示例演示
运行输出
刚好前段时间生信技能树有发一个推文介绍了中国人群的肝癌多组学队列研究 (见:一起来挖掘中国人群的肝癌多组学队列),其中配套资料就有 Singularity containers
我们下载一个最小的来简单看一下
https://zenodo.org/records/8363845
查看容器相关信息
## 查看容器构建的元信息
$singularity inspect strelka.sif
org.label-schema.build-arch: amd64
org.label-schema.build-date: Thursday_17_November_2022_17:11:39_+08
org.label-schema.license: GPLv2
org.label-schema.name: CentOS Base Image
org.label-schema.schema-version: 1.0
org.label-schema.usage.apptainer.version: 1.1.0-1.el8
org.label-schema.usage.singularity.deffile.bootstrap: docker
org.label-schema.usage.singularity.deffile.from: centos:centos7
org.label-schema.vendor: CentOS
org.opencontainers.image.created: 2020-11-13 00:00:00+00:00
org.opencontainers.image.licenses: GPL-2.0-only
org.opencontainers.image.title: CentOS Base Image
org.opencontainers.image.vendor: CentOS
## 查看容器映像文件的定义文件
singularity inspect --deffile strelka.sif
从中我们可以找到strelka具体的安装位置,也可以进入容器交互查验
更多用法,详见: