a33d99cb978c0c5179cbc9abf3322aba2225d656
singularity/Singularity\343\201\247Python\347\222\260\345\242\203(venv + pip)\343\202\222\346\247\213\347\257\211\343\201\231\343\202\213.md
... | ... | @@ -0,0 +1,57 @@ |
1 | +コンテナを起動した時にvenvをactivateする方法が分からなかったが、`%runscript`に書けば動いた。 |
|
2 | + |
|
3 | +``` |
|
4 | +BootStrap: docker |
|
5 | +From: nvcr.io/nvidia/cuda:12.6.3-base-ubuntu24.04 |
|
6 | + |
|
7 | +%setup |
|
8 | + setup_dir="${SINGULARITY_ROOTFS}/usr/local/python_env" |
|
9 | + mkdir -p "${setup_dir}" |
|
10 | + cp "./requirements.txt" "${setup_dir}/requirements.txt" |
|
11 | + |
|
12 | +%post |
|
13 | + export DEBIAN_FRONTEND=noninteractive |
|
14 | + export TZ=Asia/Tokyo |
|
15 | + |
|
16 | + apt update && \ |
|
17 | + apt install -y \ |
|
18 | + tzdata \ |
|
19 | + locales \ |
|
20 | + curl \ |
|
21 | + git \ |
|
22 | + tk-dev \ |
|
23 | + htop \ |
|
24 | + language-pack-ja \ |
|
25 | + libhdf5-serial-dev \ |
|
26 | + python3 \ |
|
27 | + python3-pip \ |
|
28 | + python3-venv |
|
29 | + |
|
30 | + export install_base_dir="/usr/local" |
|
31 | + |
|
32 | + # Setup locale |
|
33 | + localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 |
|
34 | + |
|
35 | + export python_env_install_dir="${install_base_dir}/python_env" |
|
36 | + export venv_dir="${python_env_install_dir}/.venv" |
|
37 | + cd "${python_env_install_dir}" |
|
38 | + python3 -m venv "${venv_dir}" |
|
39 | + . "${venv_dir}/bin/activate" |
|
40 | + pip install -r "${python_env_install_dir}/requirements.txt" |
|
41 | + |
|
42 | + # Clean up |
|
43 | + apt clean |
|
44 | + rm -rf /var/lib/apt/lists/* |
|
45 | + |
|
46 | +%runscript |
|
47 | + #!/bin/bash |
|
48 | + set -euo pipefail |
|
49 | + source /usr/local/python_env/.venv/bin/activate |
|
50 | + |
|
51 | + exec "$@" |
|
52 | + |
|
53 | +%environment |
|
54 | + export LANG=en_US.utf8 |
|
55 | + export DEBIAN_FRONTEND=noninteractive |
|
56 | + export TZ=Asia/Tokyo |
|
57 | +``` |
|
... | ... | \ No newline at end of file |