展开

Apptainer Definition Files

最后发布时间 : 2023-05-04 16:51:12 浏览量 :

Apptainer定义文件(简称“def文件”)就像一组蓝图,解释如何构建自定义容器。它包括有关要构建的基本操作系统或要开始的基本容器的详细信息、要安装的软件、要在运行时设置的环境变量、要从主机系统添加的文件以及容器元数据。

Apptainer定义文件分为两部分:Header和Sections

Bootstrap: docker
From: ubuntu:20.04

Preferred bootstrap agents

  • docker (images hosted on Docker Hub)
  • oras (images from supporting OCI registries)
  • localimage (images saved on your machine)
  • scratch (a flexible option for building a container from scratch)

Other bootstrap agents

  • library (images hosted on Library API Registries)
  • shub (images hosted on Singularity Hub)
  • yum (yum based systems such as CentOS and Scientific Linux)
  • debootstrap (apt based systems such as Debian and Ubuntu)
  • oci (bundle compliant with OCI Image Specification)
  • oci-archive (tar files obeying the OCI Image Layout Specification)
  • docker-daemon (images managed by the locally running docker daemon)
  • docker-archive (archived docker images)
  • arch (Arch Linux)
  • busybox (BusyBox)
  • zypper (zypper based systems such as Suse and OpenSuse)

Sections

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#