Apptainerの使用方法

ここでは例としてubuntu24.10を用います。ご使用になれるdockerイメージは以下からご覧になれます。
https://hub.docker.com

  1. コンテナの構築
    • 定義ファイルを用いてコンテナを構築する場合

      まず、以下のようなdefファイルを作ります。

      $ cat ubuntu24.def
      Bootstrap: docker
      From: ubuntu:24.10

      %post
      apt-get update
      apt-get install (必要なソフトウェア)-y

      以下のコマンドで先ほど作ったdefファイルからビルドします。

      $ apptainer build --fakeroot ubuntu24.sif ubuntu24.def
    • コンテナにログインして構築する場合

      まず、コンテナイメージをsandbox形式で用意します。

      $ apptainer build --sandbox ubuntu24 docker://ubuntu:24.10

      コンテナにログインします。

      $ apptainer shell --writable --fakeroot ubuntu24

      必要なソフトウェアをインストールし、コンテナからログアウトします。

      Apptainer> apt-get update
      Apptainer> apt-get install (必要なソフトウェア)-y
      Apptainer> exit

      sandbox形式のイメージをsifファイルに変換します。

      $ apptainer build ubuntu24.sif ubuntu24
  2. コンテナの使用

    ジョブスクリプト内で実行コマンド部分を以下のようにします。

    $ cat test.sh
    ...
    (略)
    ...
    srun apptainer exec --bind /work/<username> ubuntu24.sif (実行ファイル)

    ジョブスクリプトを実行します。

    $ sbatch test.sh