当前位置: 首页>后端>正文

工具篇-一文入门Singularity

鍐呭棰勮

  • 浠€涔堟槸杞欢瀹瑰櫒锛堟湁浠€涔堝ソ澶勶紵锛?/li>
  • 浠€涔堟槸Singularity?
  • 鏋勫缓Singularity瀹瑰櫒
  • 瀹瑰櫒鏋勫缓娴佺▼鍥?/li>

浠€涔堟槸杞欢瀹瑰櫒锛堟湁浠€涔堝ソ澶勶紵锛?/h3>

鍏充簬瀹瑰櫒鎶€鏈紝鍦ㄤ互寰€鐨勬枃绔犱腑宸蹭粙缁嶈繃涓€娆°€?br> 鏈枃閲嶇偣浠嬬粛Singularity鐨勫繀闇€鎶€鏈紝浠ュ強濡備綍鏋勫缓涓€涓睘浜庤嚜宸辩殑瀹瑰櫒锛屽湪鍏ㄦ枃鏈€鍚庯紝闄勪笂涓€寮犳瀯寤哄鍣ㄧ殑娴佺▼鍥句緵澶у鍙傝€冦€?/p>

棣栧厛浠ュ疄闄呭簲鐢ㄤ緥瀛愭潵璇达紝鍊熷姪浜庡鍣ㄦ妧鏈垜浠彲浠ュ疄鐜板摢浜涙搷浣滐紵

  • 鎵撳寘鍒嗘瀽绠¢亾锛屼娇鍏跺湪鎮ㄧ殑绗旇鏈數鑴戙€佷簯绔拰楂樻€ц兘璁$畻 (HPC) 鐜涓繍琛岋紝浠ヤ骇鐢熺浉鍚岀殑缁撴灉銆?/p>

  • 鍙戣〃璁烘枃骞跺寘鍚寚鍚戝寘鍚偍浣跨敤鐨勬墍鏈夋暟鎹拰杞欢鐨勫鍣ㄧ殑閾炬帴锛屼互渚垮叾浠栦汉鍙互杞绘澗閲嶇幇鎮ㄧ殑缁撴灉銆?/p>

  • 閫氳繃鍑犳鍑婚敭鍗冲彲瀹夎骞惰繍琛岄渶瑕佸鏉備緷璧栧叧绯诲爢鏍堢殑搴旂敤绋嬪簭銆?/p>

  • 鍒涘缓绠¢亾鎴栧鏉傜殑宸ヤ綔娴佺▼锛屽叾涓瘡涓崟鐙殑绋嬪簭閮藉簲鍦ㄤ笉鍚岀殑鎿嶄綔绯荤粺涓婅繍琛屻€?/p>

馃憠
鎯冲繀寰堝鍚屽閬囧埌杩囪繖鏍风殑鍦烘櫙

鍦ㄦ湰鍦扮數鑴戜笂璋冭瘯濂界殑鍒嗘瀽杞欢锛屽嵆浣挎槸鍚屾牱鐨勫畨瑁呮墜鍐岋紝鍦ㄥ疄楠屽/瓒呯畻涓績鐨勭數鑴戜笂锛屾娲昏涓嶄笂锛岄亣鍒板悇绉嶅鎬殑鎶ラ敊锛屼緥濡俶ake澶辫触銆乧pp棰勫鐞嗗櫒鐗堟湰涓嶆敮鎸併€佸畨瑁卲erl杞欢鐨刢pan鍖呬緷璧栧畨瑁呭け璐ョ瓑绛夈€?/p>

鍥犳锛屽浜庡垰寮€濮嬫帴瑙︿俊鎭垎鏋愮殑灏忎紮浼存潵璇达紝鎺屾彙杩欓棬鎶€鏈紝瀵逛簬瀹炵幇鍒嗘瀽绋冲畾澶嶇幇銆佸湪楂樻€ц兘鏈嶅姟鍣ㄤ笂蹇€熼厤缃垎鏋愮閬撶瓑閮芥湁闈炲父閲嶈鐨勪綔鐢?/p>

浠€涔堟槸Singularity锛?/h2>

Singularity涓嶥ocker涓€鏍凤紝閮芥槸瀹瑰櫒鎶€鏈殑涓€绉嶃€?/p>

灏界锛孲ingularity纭疄瀛樺湪涓€浜涗笉鍙拷瑙嗙殑寮辩偣锛屼緥濡傛瘮Docker鏇翠笉鎴愮啛浠ュ強鏇村皬鐨勭ぞ鍖虹敤鎴枫€?/p>

鍏剁湡姝g殑浼樺娍鍦ㄤ簬楂樻€ц兘鏈嶅姟鍣ㄤ笂閮ㄧ讲鍒嗘瀽绠¢亾鏃讹紝鏃犻渶root鏉冮檺銆佸畨鍏ㄦ€т互鍙婁綆鎴愭湰鐨勫叆闂ㄥ涔狅紝骞朵笖鑳芥棤缂濆湴灏咲ocker瀹瑰櫒杞崲涓簊ingularity瀹瑰櫒銆?/p>

鑰孌ocker鏃犺鏄鍣ㄦ瀯寤恒€佽繍琛屻€佺敓鎴愮殑缁撴灉鏂囦欢锛岄兘闇€瑕乺oot鏉冮檺锛岃繖瀵逛簬鐢ㄦ埛浣跨敤鏉ヨ闈炲父涓嶆柟渚裤€?/p>

Singularity鐨勫揩閫熷畨瑁?/h2>

棣栧厛锛屾垜浠渶瑕佺‘淇濅竴浜涘繀闇€鐨勫寘宸茬粡寰楀埌瀹夎

鍦║buntu涓紙鏍规嵁linux绯荤粺閫夋嫨锛?/p>

$ sudo apt-get update

$ sudo apt-get install -y build-essential libssl-dev uuid-dev libgpgme11-dev \
    squashfs-tools libseccomp-dev wget pkg-config git cryptsetup debootstrap

鍦–entos涓紙鏍规嵁linux绯荤粺閫夋嫨锛?/p>

$ sudo yum -y update 

$ sudo yum -y groupinstall 'Development Tools'

$ sudo yum -y install wget epel-release

$ sudo yum -y install debootstrap.noarch squashfs-tools openssl-devel \
    libuuid-devel gpgme-devel libseccomp-devel cryptsetup-luks

鎺ョ潃锛宻ingularity浣跨敤Golang缂栧啓锛屽洜姝ら渶瑕佸畨瑁匞o璇█

$ wget https://dl.google.com/go/go1.13.linux-amd64.tar.gz

$ sudo tar --directory=/usr/local -xzvf go1.13.linux-amd64.tar.gz
# 姝ゅ灏咷o娣诲姞鍒颁复鏃剁幆澧冧腑锛屽鏋滈渶瑕佸紑鏈鸿嚜鍚紝璇蜂慨鏀箏/.bashrc鏂囦欢
$ export PATH=/usr/local/go/bin:$PATH

# 瑙e帇
$ wget https://github.com/singularityware/singularity/releases/download/v3.5.3/singularity-3.5.3.tar.gz

$ tar -xzvf singularity-3.5.3.tar.gz

涔嬪悗锛屾瀯寤哄畨瑁卻ingularity

$ cd singularity

$ ./mconfig

$ cd builddir

$ make

$ sudo make install

濡傛灉甯屾湜singularity鏀寔tab琛ュ叏

$ . etc/bash_completion.d/singularity

$ sudo cp etc/bash_completion.d/singularity /etc/bash_completion.d/

鏈€鍚庯紝娴嬭瘯瀹夎

$ singularity run library://godlovedc/funny/lolcow

# 濡傛灉瀹夎姝e父锛屽垯浼氬嚭鐜颁互涓嬪唴瀹癸細
INFO:    Downloading library image
 _______________________________________
/ Excellent day for putting Slinkies on \
\ an escalator.                         /
 ---------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Singularity瀹瑰櫒涓嬭浇

鍦ㄧ嚎鐨勫鍣ㄥ簱锛?/p>

  • The Singularity Container Library, 鐢?Sylabs 寮€鍙戝拰缁存姢

  • Docker Hub, 鐢?Docker 寮€鍙戝拰缁存姢

  • Quay.io, 鐢辩孩甯藉紑鍙戝拰缁存姢

  • NGC, 鐢?NVIDIA 寮€鍙戝拰缁存姢

  • BioContainers, 鐢?Bioconda 闆嗗洟寮€鍙戝拰缁存姢

  • Amazon AWS銆丮icrosoft Azure 鍜?Google Cloud 绛変簯鎻愪緵鍟嗕篃鎷ユ湁鍙笌 Singularity 閰嶅悎浣跨敤鐨勫鍣ㄦ敞鍐岃〃

绫讳技浜巇ocker锛宻ingularity涔熻兘浠庣綉缁滀笂浣跨敤pull鍛戒护鏉ヤ笅杞藉鍣?/p>

# 浠巗ingularity搴撲笅杞藉鍣?
$ singularity pull library://godlovedc/funny/lolcow
# 涓嬭浇瀹屾垚鍚庯紝灏嗕細鐪嬭涓€涓猻if缁撳熬鐨勬枃浠讹紝杩欎釜灏辨槸singularity鐨勫鍣ㄦ枃浠?
lolcow_latest.sif
# 涔熷彲浠ヤ粠docker搴撲笅杞藉鍣?
$ singularity pull docker://godlovedc/lolcow

Singularity瀹瑰櫒浣跨敤

杩涘叆瀹瑰櫒锛?code>shell鍛戒护

$ singularity shell lolcow_latest.sif

閫€鍑哄鍣細exit鍛戒护

# 鍦ㄥ鍣ㄧ幆澧冧腑
Singularity> exit
# 灏变細杩斿洖鍒扮湡瀹炵幆澧冧笅
~>

鍦ㄥ鍣ㄥ唴鎵ц浠诲姟锛?code>exec鍛戒护

$ singularity exec lolcow_latest.sif cowsay 'How did you get out of the container?'
 _______________________________________
< How did you get out of the container>
 ---------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

杩愯瀹瑰櫒锛?code>run鍛戒护

$ singularity run lolcow_latest.sif
# 姝ゅ鐨剅un锛屽疄闄呬笂鏄皟鐢ㄥ鍣ㄥ唴鐨勪竴涓猺unscript鐨勭壒娈婃枃浠?

# 妫€鏌ュ鍣ㄥ唴鐨剅unscript鏂囦欢
$ singularity inspect --runscript lolcow_latest.sif
#!/bin/sh

    fortune | cowsay | lolcat
    
# 姝ゅ锛屼篃鍙互鍍忚繍琛岃蒋浠朵竴鏍锋潵浣跨敤瀹瑰櫒锛屼緥濡?
./lolcow_latest.sif

鏋勫缓Singularity瀹瑰櫒

瑕佹瀯寤轰竴涓鍣紝蹇呴』浣跨敤build鍛戒护

涓€涓爣鍑嗙殑瀹瑰櫒寮€鍙戝懆鏈熶负锛?/p>

  1. 缂栧啓涓€涓彲鍐欑殑瀹瑰櫒锛坰andbox锛?/p>

  2. 浣跨敤--writeable杩涘叆瀹瑰櫒锛屼互浜や簰鏂瑰紡瀵瑰鍣ㄨ繘琛屼慨鏀?/p>

  3. 瀵规枃浠惰繘琛屼慨鏀?/p>

  4. 閲嶆柊build

  5. 閲嶅鍓嶄袱姝ワ紝鐩村埌瀹瑰櫒鍙樻垚鎴戜滑鏈熸湜鐨勭姸鎬?/p>

  6. build骞朵繚瀛樺鍣紝浠ヤ緵鐢熶骇浣跨敤

渚嬪鎴戜滑鎵嬪ご宸茬粡鏈変竴涓幇鎴愮殑recipes锛堢敤浜巄uild鐨勫懡浠ゆ枃浠讹級

BootStrap: debootstrap
OSVersion: stable
MirrorURL: http://ftp.us.debian.org/debian/

%runscript
    echo "This is what happens when you run the container..."

%post
    echo "Hello from inside the container"
    apt-get -y --allow-unauthenticated install vim

鍦ㄨ繖涓枃浠朵腑锛?寮€澶寸殑閫氬父琛ㄧず鍦ㄦ瀯寤鸿繃绋嬩腑璧风潃涓€瀹氱壒娈婁綔鐢紝鍏蜂綋鍙互鍙傝€冩枃妗o細https://docs.sylabs.io/guides/3.5/user-guide/definition_files.html

甯哥敤鐨勭鍙锋湁锛?/p>

%post(鎵ц鍛戒护锛屽涓嬭浇銆佸畨瑁呫€佺紪鍐欓厤缃枃浠躲€佸垱寤虹洰褰曠瓑)

%files(灏嗘枃浠跺鍒跺埌瀹瑰櫒涓?

%test(鏋勫缓瀹屾垚鍚庯紝娴嬭瘯瀹瑰櫒)

%environment(璁剧疆鐜鍙橀噺锛岀被浼间簬淇敼.bashrc)

%runscript(姣旇緝鐗规畩锛屽湪鍛煎嚭瀹瑰櫒鏃讹紝鍙互鑷姩鎵ц璁″垝鐨勪换鍔?

浠庡ご鏋勫缓涓€涓鍣?/h3>

瀵逛簬鏂版墜鑰岃█锛岄€氬父鍦╞uild瀹瑰櫒鏃讹紝闇€瑕佺粰鍑?-sandbox閫夐」锛岃繖鍦ㄦ垜浠繕涓嶇煡閬撳鍣ㄥ紑鍙戝叿浣撻渶瑕佸寘鍚粈涔堟枃浠剁殑鏃跺€欙紝闈炲父鏈夌敤

寮€濮媌uild瀹瑰櫒

$ sudo singularity build --sandbox lolcow lolcow.def

杩愯瀹屾垚鍚庯紝浼氬湪褰撳墠鐩綍涓嬬湅鍒颁竴涓猯olcow鏂囦欢

瀵瑰鍣ㄨ繘琛屾帰绱㈠拰淇敼

$ sudo singularity shell --writable lolcow
Singularity> apt-get update
Singularity> apt-get install -y fortune cowsay lolcat

姝ゆ椂鍙互鐪嬪埌搴旂敤绋嬪簭鎴愬姛瀹夎锛屼絾濡傛灉娌℃湁浣跨敤--writeable鍙傛暟锛岄偅涔堝湪杩涘叆瀹瑰櫒鍚庯紝鎵ц瀹夎鍛戒护锛岄€氬父浼氳鍛婄煡杩欎簺鏂囦欢閮芥槸read-only锛屼笉鍙慨鏀?/p>

闇€瑕佽鏄庣殑鏄紝涓巇ocker绫讳技锛屽湪瀹瑰櫒涓繘琛岀殑鎿嶄綔锛屽湪閫€鍑哄鍣ㄥ悗锛岃繖浜涗慨鏀瑰苟涓嶄細淇濆瓨锛屽鏋滆浣胯繖浜涗慨鏀规案涔呯敓鏁堬紝灏遍渶瑕佸皢杩欎簺鎿嶄綔鍔犲叆鍒板畾涔夋枃浠朵腑锛岄噸鏂癰uild

浠庣幇鏈夊鍣ㄦ瀯寤?/h3>

浠庣幇鏈夊鍣ㄦ瀯寤猴紝闇€瑕佹敞鎰忕殑鏄紝瑕佷慨鏀筨uild瀹氫箟鏂囦欢鐨刪eader

渚嬪闇€瑕佷互瀹瑰櫒搴撲腑鐜版湁鐨勫鍣ㄤ綔涓鸿捣鐐?/p>

# 渚嬪浠ebian涓鸿捣鐐?
BootStrap: library
From: debian
# 鎴栬€呬粠docker hub涓婄殑debian鍚姩
Bootstrap: docker
From: debian
# 鍐嶆垨鑰呬互鏈湴鏂囦欢绯荤粺涓婄殑鍩虹瀹瑰櫒鍚姩
Bootstrap: localimage
From: /home/test/debian.sif

涓庝粠澶存瀯寤哄鍣ㄧ浉姣旓紝浠庣幇鏈夊鍣ㄦ瀯寤虹殑鏈€澶уソ澶勬槸涓嶉渶瑕乺oot鏉冮檺

$ singularity build debian3.sif debian2.sif

瀹夊叏鐨勬瀯寤哄鍣?/h3>

鍦╯ingularity涓紝鎻愪緵浜?-fakeroot閫夐」锛屽彲浠ヤ互鏇村畨鍏ㄧ殑鏂瑰紡鍦ㄥ鍣ㄤ腑浣跨敤root鏉冮檺鏉uild瀹瑰櫒

$ singularity build --fakeroot container.sif container.def

瀹瑰櫒鎸傝浇涓绘満鏂囦欢

榛樿鎯呭喌涓嬶紝瀹瑰櫒杩愯鍚庝細鑷姩缁戝畾涓绘満鐨勫嚑涓洰褰曪紝鍖呮嫭锛?/p>

$HOME

/tmp

/proc

/sys

/dev

姝ゅ锛屼篃鍙互浣跨敤--bind/-B/SINGULARITY_BINDPATH鏉ユ寚瀹氶渶瑕佺粦瀹氱殑鍏朵粬鐩綍

鑷虫锛屼綘宸茬粡鎺屾彙浜嗘瀯寤轰竴涓猻ingularity瀹瑰櫒鐨勫繀椤绘妧鑳戒簡锛屽彲浠ュ幓灏濊瘯鏋勫缓涓€涓睘浜庤嚜宸辩殑瀹瑰櫒銆?/p>

瀹瑰櫒鏋勫缓娴佺▼鍥?/h3>
工具篇-一文入门Singularity,第1张

鏈枃鐢卞崥瀹竴鏂囧鍙戝钩鍙?OpenWrite 鍙戝竷锛?/p>


https://www.xamrdz.com/backend/38g1940389.html

相关文章: