Apptainer定义文件(简称“def文件”)就像一组蓝图,解释如何构建自定义容器。它包括有关要构建的基本操作系统或要开始的基本容器的详细信息、要安装的软件、要在运行时设置的环境变量、要从主机系统添加的文件以及容器元数据。
Apptainer定义文件分为两部分:Header和Sections
Bootstrap: docker From: ubuntu:20.04
Bootstrap: docker From: ubuntu:18.04 Stage: build %setup touch /file1 touch ${APPTAINER_ROOTFS}/file2 %files /file1 /file1 /opt %environment export LISTEN_PORT=12345 export LC_ALL=C %post apt-get update && apt-get install -y netcat NOW=`date` echo "export NOW=\"${NOW}\"" >> $APPTAINER_ENVIRONMENT %runscript echo "Container was created $NOW" echo "Arguments received: $*" exec echo "$@" %startscript nc -lp $LISTEN_PORT %test grep -q NAME=\"Ubuntu\" /etc/os-release if [ $? -eq 0 ]; then echo "Container base is Ubuntu as expected." else echo "Container base is not Ubuntu." exit 1 fi %labels Author alice Version v0.0.1 %help This is a demo container used to illustrate a def file that uses all supported sections.
conda activate your_env conda env export > environment.yml
Bootstrap: docker From: continuumio/miniconda3 %files environment.yml %post /opt/conda/bin/conda env create -f environment.yml %runscript exec /opt/conda/envs/$(head -n 1 environment.yml | cut -f 2 -d ' ')/bin/"$@"
sudo singularity build conda.sif Singularity
singularity run conda.sif ipython
参考: https://apptainer.org/docs/user/main/definition_files.html#