• Singularity容器


    """参考文档
    https://apptainer.org/user-docs/master/build_a_container.html
    """
    
    # 通过文件构建容器,相当于docker的Dockerfile
    ## 创建一个Singularity文件
    >>> vim Singularity
    Bootstrap: docker
    """
    其中Bootstrap可以是:
    shub(images hosted on Singularity Hub).
    docker(images hosted on Docker Hub).
    localimage(images saved on your machine).
    yum(yum based systemd such as Centos and Scientific Linux)等
    """
    From: ubuntu:18.04
    Stage: build
    
    %setup
    """
    在构建过程中,该%setup部分中的命令首先在安装基本操作系统后在容器外的主机系统上执行,可以在该部分中使用$SINGULARITY_ROOTFS环境变量引用容器文件系统
    """
        touch /file1
        touch ${SINGULARITY_ROOTFS}/file2
    
    %files
    """
    允许您将文件复制到容器中,比使用该%setup部分更安全
    """
        /file1
        /file1 /opt
    
    %environment
    """
    允许您定义将在运行时设置的环境变量
    """
        export LISTEN_PORT=12345
        export LC_ALL=C
    
    %post
    """
    你可以使用git和wget等工具从互联网上下载文件,安装新的软件和库,编写配置文件,创建新的目录等。类似于dockerfile中的Run
    """
        apt-get update && apt-get install -y netcat
        NOW=`date`
        echo "export NOW=\"${NOW}\"" >> $SINGULARITY_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
    """
    用于将元数据添加到/.singularity.d/labels.json容器内的文件中。
    """
        Author d@sylabs.io
        Version v0.0.1
    
    %help
    """
    该部分中的任何文本%help都会被转录到容器中的元数据文件中。然后可以使用run-help命令显示此文本
    """
        This is a demo container used to illustrate a def file that uses all
        supported sections.
    
    
    # 构建镜像
    >>> singularity build ubuntu-test.image Singularity
    
    # 运行容器
    >>> singularity run ubuntu-test.image
    
  • 相关阅读:
    redis在Linux的下载和安装
    redis 安装启动及设置密码windows
    Lambda学习---方法引用和其他基本应用
    Lambda学习---StreamApi使用
    java对象的访问定位
    java对象是如何创建的
    通过“减少内存”的方式解决内存溢出的问题
    springmvc配置中,mapper一直依赖注入不进去的问题记录
    为什么要简化代码书写
    压力测试工具
  • 原文地址:https://www.cnblogs.com/weiweivip666/p/15899897.html
Copyright © 2020-2023  润新知