macOS上で動作する Singularity を利用してみる
Sylabs.ioで公開された、Singularity Desktop for macOS (Alpha Preview)を利用してみる
ホストOSの環境
利用しているmacOSのバージョンは以下の通り
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.4
BuildVersion: 18E226
dmgファイルのダウンロードとインストール
48.3MBのsingularity-desktop-0.0.2alpha.dmgをダウンロード
インストール手順の詳細は、Singularity Desktop for macOS (Alpha Preview)を参照
- Downloadsフォルダーの
singularity-desktop-0.0.2alpha.dmg
をダブルクリック - パッケージのアイコン
SingularityDesktop-0.0.2alpha.pkg
をダブルクリック- Singularityのアイコンから矢印がパッケージに伸びている部分については、このアイコンをドラッグ&ドロップするものと誤解を招くのではないかと思う
- インストーラーの指示に従ってインストール
- インストール先を変更しては駄目
-
singularity-desktop-0.0.2alpha.dmg
を消さない- Singularityをアンインストールする際に利用されると思われる
uninstall.tool
が含まれている
- Singularityをアンインストールする際に利用されると思われる
Singularityの動作確認
singularity が正常にインストールされた事を確認する
$ singularity
Usage:
singularity [global options...] <command>
Available Commands:
build Build a Singularity image
exec Run a command within a container
key Manage OpenPGP keys
pull Pull an image from a URI
push Upload image to the provided library (default is "cloud.sylabs.io")
remote Manage singularity remote endpoints
run Run the user-defined default command within a container
search Search a Library for images
shell Run a shell within a container
sign Attach a cryptographic signature to an image
test Run the user-defined tests within a container
verify Verify cryptographic signatures attached to an image
version Show the version for Singularity
Run 'singularity --help' for more detailed usage information.
Version の確認
$ singularity version
3.2.0-rc2
ここまでの手順でSingularity Version 3.2.0-rc2
がインストールされた事がわかる
Singularity コンテナの実行
Singularity Desktop for macOS (Alpha Preview)の手順にしたがって、lolcow
をsingularity コンテナを利用して実行する
$ singularity run library://godlovedc/funny/lolcow
WARNING: No default remote in use, falling back to https://library.sylabs.io
INFO: Downloading library image
89.24 MiB / 89.24 MiB [==============================================================] 100.00% 381.65 KiB/s 3m59s
______________________________________
/ Try to value useful qualities in one \
\ who loves you. /
--------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
[ 1.517274] reboot: Power down
コンテナのLinuxの情報を確認してみる
$ singularity exec library://godlovedc/funny/lolcow uname -a
WARNING: No default remote in use, falling back to https://library.sylabs.io
Linux (none) 4.19.10 #1 SMP Mon Apr 8 00:07:40 CDT 2019 x86_64 x86_64 x86_64 GNU/Linux
[ 1.244129] reboot: Power down
Dockerイメージの取得とその実行
Singularity Desktop for macOS (Alpha Preview)の手順に従って、Dockerイメージを利用してlolcow
を実行する
dockerイメージのダウンロード後 OCI(Open Container Initiative)フォーマットから SIF(Singularity Image Format: Singularity V3.0以上の標準フォーマット)に変換されて実行される
$ singularity run docker://godlovedc/lolcow
INFO: Converting OCI blobs to SIF format
INFO: Starting build...
Getting image source signatures
Copying blob sha256:9fb6c798fa41e509b58bccc5c29654c3ff4648b608f5daa67c1aab6a7d02c118
45.33 MiB / 45.33 MiB [====================================================] 4s
Copying blob sha256:3b61febd4aefe982e0cb9c696d415137384d1a01052b50a85aae46439e15e49a
848 B / 848 B [============================================================] 0s
Copying blob sha256:9d99b9777eb02b8943c0e72d7a7baec5c782f8fd976825c9d3fb48b3101aacc2
621 B / 621 B [============================================================] 0s
Copying blob sha256:d010c8cf75d7eb5d2504d5ffa0d19696e8d745a457dd8d28ec6dd41d3763617e
853 B / 853 B [============================================================] 0s
Copying blob sha256:7fac07fb303e0589b9c23e6f49d5dc1ff9d6f3c8c88cabe768b430bdb47f03a9
169 B / 169 B [============================================================] 0s
Copying blob sha256:8e860504ff1ee5dc7953672d128ce1e4aa4d8e3716eb39fe710b849c64b20945
53.75 MiB / 53.75 MiB [====================================================] 9s
Copying config sha256:73d5b1025fbfa138f2cacf45bbf3f61f7de891559fa25b28ab365c7d9c3cbd82
3.33 KiB / 3.33 KiB [======================================================] 0s
Writing manifest to image destination
Storing signatures
INFO: Creating SIF file...
INFO: Build complete: /Users/percipere/.singularity/cache/oci-tmp/a692b57abc43035b197b10390ea2c12855d21649f2ea2cc28094d18b93360eeb/lolcow_latest.sif
_________________________________
/ AWAKE! FEAR! FIRE! FOES! AWAKE! \
| |
| FEAR! FIRE! FOES! |
| |
| AWAKE! AWAKE! |
| |
\ -- J. R. R. Tolkien /
---------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
[ 1.547216] reboot: Power down
2回目は先程作製されたキャッシュフォルダー上のlolcow_latest.sifが利用されるので直ぐに実行できる
$ singularity run docker://godlovedc/lolcow
_______________________________________
/ Whenever you find that you are on the \
| side of the majority, it is time to |
| reform. |
| |
\ -- Mark Twain /
---------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
[ 1.562611] reboot: Power down
alpine linuxのDockerイメージを実行
$ singularity run docker://alpine cat /etc/alpine-release
3.9.3
[ 1.246163] reboot: Power down
shellコマンドの実行
shell
コマンドを利用して、コンテナ内部のシェルを確認してみる
$ singularity shell library://godlovedc/funny/lolcow
WARNING: No default remote in use, falling back to https://library.sylabs.io
Singularity lolcow_latest.sif:~> pwd
/Users/percipere
Singularity lolcow_latest.sif:~> echo $0
/bin/bash
singularityのキャッシュファイル
デフォルトでは、$HOME/.singularity
以下にキャッシュファイルが配置される
動作制限に関するマニュアル記述事項との違い
When mounting directories from the host, the directory name of two mounts cannot be the same.
singularity exec -B /tmp -B /var/tmp docker://godlovedc/lolcow
ホスト上の同じ名前の複数のディレクトリ(この例では/tmp
と/var/tmp
)をマウントすると正しく動作しないとあるが、特に問題は生じていないように見える
$ singularity exec -B /tmp -B /var/tmp docker://godlovedc/lolcow ls /tmp /var/tmp
/tmp:
Sophos_Support_8hMTcx com.apple.launchd.0w9OPtu5WR mysqlx.sock
Sophos_Support_UZn96q com.apple.launchd.Gjbeiv6Lob powerlog
Sophos_Support_lX7UYD com.apple.launchd.KYbaYnMtYG
Sophos_Support_snXtQP mysql.sock
/var/tmp:
-skb.kc
filesystemui.socket
quicklookd_exit_4CC4719F-08D2-4796-B49F-A0A87D416D39.tailspin
[ 1.283264] reboot: Power down
Dockerとの動作の違い
Singularity の場合
デフォルトのディレクトリは/Users/$HOME
となるので /
を明示的に指定
$ singularity exec docker://alpine ls -aF /
./ Users/ media/ singularity@
../ bin/ mnt/ srv/
.exec@ dev/ opt/ sys/
.run@ environment@ proc/ tmp/
.shell@ etc/ root/ usr/
.singularity.d/ home/ run/ var/
.test@ lib/ sbin/
[ 1.256518] reboot: Power down
- .exec
- .run
- .shell
- .test
- environment
- singularity
等のリンクはSingularity固有のもの
ユーザはroot
では無い
singularityのコンテナの内部でroot権限が必要なら、ホスト上でもroot
権限が必要
Docker の場合
$ docker run -it alpine /bin/sh
/ # ls -aF
./ dev/ media/ root/ sys/
../ etc/ mnt/ run/ tmp/
.dockerenv* home/ opt/ sbin/ usr/
bin/ lib/ proc/ srv/ var/
/ # whoami
root
dockerfileでユーザーを追加していない場合にはコンテナ内のroot
ユーザー権限でコンテナが利用される
ホストのディレクトリをマウントしている場合、ファイルに対する権限はホストのroot
の権限で実施される(つまり、どのファイルも読み書き可能な状態となる)
Singularity Desktop for macOS (Alpha Preview)を利用することで、お手軽にmacOS上でSingularityが利用できた
今回はここまで