创建并使用sigularity images
2024-07-16 17:36:50 # easy

容器镜像可以很好的帮我们储存,分享代码运行环境,这里简单分享自定义的sigularity image的创建方法和使用

0.前提

  1. 在系统上安装sigularity
  2. 如果要上传远程仓库,需要先登录

1.创建Singularity Definition File

创建一个Singularity Definition File(my_test_image.def):

主要是在%post标签下添加我们所需要的软件/模块/包的安装命令,安装命令需要与From后的平台相匹配,Bootstrap表明了文件的储存位置,如果不想上传远程储存,可以用localimage

1
2
3
4
5
6
7
8
9
10
11
12
13
Bootstrap: docker
From: ubuntu:20.04

%post
apt-get -y update && apt-get install -y python3
apt-get -y update && apt-get install -y samtools
apt-get -y update && apt-get install -y multiqc


%runscript
samtools -v
multiqc -v

2.创建环境并上传

这里根据Bootstrap下的标签上传到不同的远程仓库

1
singularity build --remote my_test_image.sif my_test_image.def

3.使用环境

将环境从远程仓库下载下来:

1
singularity pull my_test_image.sif docker://my_test_image

直接run环境会执行 %runscript 标签下的脚本

1
singularity run test_image.sif

执行其他命令:

1
2
singularity run my_test_image.sif samtools index test.bam

镜像仓库

galaxy project

参考资料

Introduction to containers and singularity
Apptainer