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

我们需要两样东西:

得到这些信息后, 使用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来执行.

其他操作可以查看GitHub - cp2k/cp2k-containers: CP2K containers