简单使用介绍
BioNote 2021-11-20
singularity
# 参考
# 前言
有些HPC由于权限问题不允许使用docker,改用singularity容器系统,简单记录下用法
# 相较于docker优缺点
# 优点
- 和现有系统保持一致:继承系统用户权限、网络等
- 无需和docker一样开启一个容器,直接基于镜像文件可以执行命令
- 仅提供运行环境,不使用时不占用资源
# 缺点
- 资料少,使用者少;遇到问题可能别人没碰到过,要自己踩坑
# 镜像文件
Singularity 镜像文件(Singularity Image File, sif)是一种内容只读的文件格式,其文件内容不能被修改。
# 下载镜像
Singularity 可以从 Singularity Hub (以 shub:// 开头)或者 Docker Hub (以 docker:// 开头)来获取镜像
# 从 Singularity Hub build 镜像
singularity -d build lolcow.simg shub://GodloveD/lolcow
# 从 Docker Hub build 镜像
singularity -d build lolcow.simg docker://godlovedc/lolcow
singularity -d build centos.simg docker://centos
singularity -d build ubuntu.simg docker://ubuntu
1
2
3
4
5
6
7
2
3
4
5
6
7
视配置而定,有些环境需要加SINGULARITY_NOHTTPS=1
SINGULARITY_NOHTTPS=1 singularity -d build centos_test.simg docker://centos
1
# 镜像使用
# 直接执行命令
singularity exec centos_test.simg python test.py
1
# 进入交互界面
singularity shell centos_test.simg
1
上述命令会自动挂载当前目录,主动挂载目录的参数为-B
singularity shell -B /pengbing ~/test/centos_test.simg
singularity shell -B /pengbing:/test ~/test/centos_test.simg
1
2
2
对挂载目录的操作的权限与用户系统权限一致
退出交互命令:exit
# nextflow调用
nextflow脚本:
process get_txt{
output:
file "*.txt" into next
"""
echo "this is test" > hello.txt
"""
}
process add_text{
input:
file hello from next
"""
cat $hello > final.txt
cp final.txt /pb
"""
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
nextflow config
process.container = '/home/pengbing/centos_test.simg'
singularity.enabled = true
singularity.runOptions='-B /test:/pb -B /home/pengbing'
1
2
3
2
3
挂载后的目录/test生成了final.txt