Apptainer是一个无需特权的容器平台, 可以运行在任何对权限有所限制的平台, 如HPC 服务器等.
1. 安装Apptainer
curl -s https://raw.githubusercontent.com/apptainer/apptainer/main/tools/install-unprivileged.sh | bash -s - /home/happy_ling/apptainer
执行如上命令后即可自动安装, 期间若出现超时 404等错误则需要挂代理.
安装到指定目录后, 使用apptainer
命令即可验证
$ apptainer
Usage:
apptainer [global options...] <command>
Available Commands:
build Build an Apptainer image
cache Manage the local cache
capability Manage Linux capabilities for users and groups
checkpoint Manage container checkpoint state (experimental)
completion Generate the autocompletion script for the specified shell
config Manage various apptainer configuration (root user only)
delete Deletes requested image from the library
exec Run a command within a container
inspect Show metadata for an image
instance Manage containers running as services
key Manage OpenPGP keys
oci Manage OCI containers
overlay Manage an EXT3 writable overlay image
plugin Manage Apptainer plugins
pull Pull an image from a URI
push Upload image to the provided URI
remote Manage apptainer remote endpoints, keyservers and OCI/Docker
registry credentials
run Run the user-defined default command within a container
run-help Show the user-defined help for an image
search Search a Container Library for images
shell Run a shell within a container
sif Manipulate Singularity Image Format (SIF) images
sign Add digital signature(s) to an image
test Run the user-defined tests within a container
verify Verify digital signature(s) within an image
version Show the version for Apptainer
Run 'apptainer --help' for more detailed usage information.
我们只关注下面这几个命令:
- 拉取镜像
apptainer pull <image.sif> <source>
- 运行镜像
apptainer run <image.sif> [command]
, 或直接./image.sif
.
2. 拉取cp2k
我们需要两样东西:
- 镜像名称及TAG, 用于确定某个应用的名称和版本. 如
The name of a docker container indicates CP2K version, MPI implementation (MPICH or OpenMPI), target CPU (
generic
,haswell
, orskylake-avx512
), CUDA support, and cp2k binary version (e.g.psmp
for MPI parallelized with OpenMP support). If you don’t know your CPU model, then try the CPU targetgeneric
(NEHALEM) first or simply chooselatest
如此处的cp2k:2025.1_openmpi_generic_psmp
, 如果想拉取最新版, 可使用latest TAG–cp2k:latest
(https://hub.docker.com/r/cp2k/cp2k/tags - 仓库网址, 来源自官方仓库的可以省略网址, 使用如
docker://cp2k/cp2k:latest
的形式来下载某镜像.- 但是由于国内网络的原因, 我们需要使用一些镜像网址.
- 如:
docker://docker.xiaogenban1993.com/cp2k/cp2k:latest
- 这些网址可以在国内可用Docker镜像源加速器/DockerHub镜像汇总(2025年6月10日) - 文武科技柜, 和GitHub - dongyubin/DockerHub: 2025年6月更新,目前国内可用Docker镜像源汇总,DockerHub国内镜像加速列表,🚀DockerHub镜像加速器 中查看
得到这些信息后, 使用apptainer pull cp2k-2025.1.sif docker://docker.xiaogenban1993.com/cp2k/cp2k:cp2k:2025.1_openmpi_generic_psmp
来将指定版本的cp2k下载到cp2k-2025.1.sif
文件中, 这个文件是可以直接执行的.
后续任何可在docker hub中搜索到的docker镜像均可以使用这种方式来下载并使用.
3. 使用cp2k
可以使用命令apptainer run cp2k-2025.1.sif cp2k
来执行cp2k, 用法与编译安装的cp2k
相同.
也可以直接./cp2k-2025.1.sif
来执行.