Docker,SingularityをUbuntu20.04にインストール

はじめに

以前この記事でWorkstationにUbuntu 20.04をクリーンインストールしたことを書いた。そのWorkstationにDocker, Singularityをインストールしたので、自身のメモのため、以下に記事としてまとめる。

参考ページ

Dockerインストール

パッケージリストを更新、インストールに必要なパッケージをインストール

$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common

公式DockerリポジトリのGPGキーを追加

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Dockerリポジトリを追加、パッケージングデータベースを更新

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
$ sudo apt update

Dockerリポジトリよりインストール

$ sudo apt install docker-ce

デーモン起動確認でインストールを確認

$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset>
     Active: active (running) since Tue 2021-08-24 10:34:27 JST; 1min 8s ago
TriggeredBy: ● docker.socket
・・・以下略・・・

起動確認

※ sudoなしで、Dockerを起動できる設定はしなかったので、dockerコマンドの前にsudo必須。

$ sudo docker run hello-world
[sudo] xxxx のパスワード: 
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
・・・以下略・・・

「–gpus all」オプションで次のようなエラーが発生した場合

docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].

上にあげた記事を参考に、次のシェルスクリプト(nvidia-container-runtime-script.sh)を用意し、

curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \
  sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update
# Execute the script

その上で、次を順次実行する。

$ sh nvidia-container-runtime-script.sh
$ sudo apt-get install nvidia-container-runtime

正常に終了すれば、次の通り。

$ sudo docker run -it --rm --gpus all ubuntu nvidia-smi
[sudo] xxxx のパスワード: 
Fri Sep  3 14:47:38 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.91.03    Driver Version: 460.91.03    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX TITAN   Off  | 00000000:04:00.0 Off |                  N/A |
| 30%   33C    P8    13W / 250W |     11MiB /  6083MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  Quadro K2000        Off  | 00000000:05:00.0  On |                  N/A |
| 30%   31C    P8    N/A /  N/A |    101MiB /  1996MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

Singularityインストール

関連するパッケージをインストール

$ sudo apt-get update && sudo apt-get install -y \
> build-essential \
> uuid-dev \
> libgpgme-dev \
> squashfs-tools \
> libseccomp-dev \
> wget \
> pkg-config \
> git \
> cryptsetup-bin

goをインストール

$ export VERSION=1.14.12 OS=linux ARCH=amd64 && \
wget https://dl.google.com/go/go$VERSION.$OS-$ARCH.tar.gz && \
sudo tar -C /usr/local -xzvf go$VERSION.$OS-$ARCH.tar.gz && \
rm go$VERSION.$OS-$ARCH.tar.gz

goのPATHを設定

$ echo 'export GOPATH=${HOME}/go' >> ~/.bashrc && \
> echo 'export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin' >> ~/.bashrc && \
> source ~/.bashrc

singularityをダウンロード

$ export VERSION=3.8.0 && # adjust this as necessary \
> wget https://github.com/sylabs/singularity/releases/download/v${VERSION}/singularity-ce-${VERSION}.tar.gz && \
> tar -xzf singularity-ce-${VERSION}.tar.gz && \
> cd singularity-ce-${VERSION}

singularityをコンパイル

$ ./mconfig && \
> make -C ./builddir && \
> sudo make -C ./builddir install

インストール確認のため、Sylabs Cloud libraryのコンテナを起動

$ singularity exec library://alpine cat /etc/alpine-release
3.14.0

今後について

およそ一年前、この記事では、dockerコンテナからsingularityコンテナ(sifファイル)を作る記事を書いた。

今後は、jupyterlabやNVIDIA HPC SDKのsingularityコンテナをdefinition fileから作りたい。


も参照してください