1. 依赖包安装
sudo apt-get install -y \
build-essential \
libseccomp-dev \
pkg-config \
uidmap \
squashfs-tools \
fakeroot \
cryptsetup \
tzdata \
curl wget git
# golang
wget https://go.dev/dl/go1.22.4.linux-amd64.tar.gz
sudo tar -xvf go1.22.4.linux-amd64.tar.gz -C /usr/local
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc
2. 下载apptainer
git clone https://github.com/apptainer/apptainer.git
cd apptainer
git checkout v1.3.2
3. 编译
./mconfig -p $PWD/dist
cd $(/bin/pwd)/builddir
make -j
make install
完成后apptainer安装在apptainer/dist目录中,如下图
使用
# 设置环境变量
export PATH=$PWD:$PATH
尝试构建一个镜像
apptainer build ubuntu-latest.sif docker://ubuntu:latest
3.1 运行某个命令
apptainer run --nv ubuntu-latest.sif id
3.2 进入交互式的命令行
apptainer shell --nv ubuntu-latest.sif
3.3 在后台运行容器实例
# 启动
apptainer instance start ubuntu-latest.sif ub_24
# 执行命令
apptainer run instance://ub_24 ps aux
# 停止
apptainer instance stop ub_24
Demo
基于apptainer构建一个anaconda环境
apptainer build anaconda3.sif docker://continuumio/anaconda3
进入交互式shell开启jupyterlab
apptainer shell anaconda3.sif
jupyter-lab --no-browser --ip 10.123.21.12
在浏览器中打开jupyterlab