(瓒呯骇璇︾粏)Docker 鏋舵瀯鍘熺悊鍙婄畝鍗曚娇鐢╗鏈夐厤濂楄棰慮
Posted java澶ф暟鎹慨鐐间箣閬?/a>
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(瓒呯骇璇︾粏)Docker 鏋舵瀯鍘熺悊鍙婄畝鍗曚娇鐢╗鏈夐厤濂楄棰慮相关的知识,希望对你有一定的参考价值。
姣忔櫄涔濈偣: 鎶€鏈共璐?馃憠 蹇呭畾濂変笂
鍝堝柦锛屽悇浣嶆柊鏉ョ殑灏忎紮浼翠滑锛屽ぇ瀹跺ソ锛佺敱浜庡叕浼楀彿鍋氫簡鏀圭増锛屼负浜嗕繚璇佸叕浼楀彿鐨勮祫婧愯兘鍑嗘椂鎺ㄩ€佸埌浣犳墜閲岋紝澶у璁板緱灏嗗挶浠殑鍏紬鍙?nbsp;鍔犳槦鏍囩疆椤?/span> 锛屽湪姝ょ湡璇氱殑琛ㄧず鎰熻阿
www.cnblogs.com/zhangxingeng/p/11236968.html
涓€銆佺畝浠?/span>
1銆佷簡瑙ocker鐨勫墠鐢烲XC
LXC涓篖inux Container鐨勭畝鍐欍€傚彲浠ユ彁渚涜交閲忕骇鐨勮櫄鎷熷寲锛屼互渚块殧绂昏繘绋嬪拰璧勬簮锛岃€屼笖涓嶉渶瑕佹彁渚涙寚浠よВ閲婃満鍒朵互鍙婂叏铏氭嫙鍖栫殑鍏朵粬澶嶆潅鎬с€傜浉褰撲簬C++涓殑NameSpace銆傚鍣ㄦ湁鏁堝湴灏嗙敱鍗曚釜鎿嶄綔绯荤粺绠$悊鐨勮祫婧愬垝鍒嗗埌瀛ょ珛鐨勭粍涓紝浠ユ洿濂藉湴鍦ㄥ绔嬬殑缁勪箣闂村钩琛℃湁鍐茬獊鐨勮祫婧愪娇鐢ㄩ渶姹傘€?/span>
涓庝紶缁熻櫄鎷熷寲鎶€鏈浉姣旓紝瀹冪殑浼樺娍鍦ㄤ簬锛?/span>
涓庡涓绘満浣跨敤鍚屼竴涓唴鏍革紝鎬ц兘鎹熻€楀皬锛?/span>
涓嶉渶瑕佹寚浠ょ骇妯℃嫙锛?/span>
涓嶉渶瑕佸嵆鏃?Just-in-time)缂栬瘧锛?/span>
瀹瑰櫒鍙互鍦–PU鏍稿績鐨勬湰鍦拌繍琛屾寚浠わ紝涓嶉渶瑕佷换浣曚笓闂ㄧ殑瑙i噴鏈哄埗锛?/span>
閬垮厤浜嗗噯铏氭嫙鍖栧拰绯荤粺璋冪敤鏇挎崲涓殑澶嶆潅鎬э紱
杞婚噺绾ч殧绂伙紝鍦ㄩ殧绂荤殑鍚屾椂杩樻彁渚涘叡浜満鍒讹紝浠ュ疄鐜板鍣ㄤ笌瀹夸富鏈虹殑璧勬簮鍏变韩銆?/span>
鎬荤粨锛歀inux Container鏄竴绉嶈交閲忕骇鐨勮櫄鎷熷寲鐨勬墜娈点€?/span>
Linux Container鎻愪緵浜嗗湪鍗曚竴鍙帶涓绘満鑺傜偣涓婃敮鎸佸涓浉浜掗殧绂荤殑server container鍚屾椂鎵ц鐨勬満鍒躲€侺inux Container鏈夌偣鍍廲hroot锛屾彁渚涗簡涓€涓嫢鏈夎嚜宸辫繘绋嬪拰缃戠粶绌洪棿鐨勮櫄鎷熺幆澧冿紝浣嗗張鏈夊埆浜庤櫄鎷熸満锛屽洜涓簂xc鏄竴绉嶆搷浣滅郴缁熷眰娆′笂鐨勮祫婧愮殑铏氭嫙鍖栥€?/span>
2銆丩XC涓巇ocker浠€涔堝叧绯伙紵
docker骞朵笉鏄疞XC鏇夸唬鍝侊紝docker搴曞眰浣跨敤浜哃XC鏉ュ疄鐜帮紝LXC灏唋inux杩涚▼娌欑洅鍖栵紝浣垮緱杩涚▼涔嬮棿鐩镐簰闅旂锛屽苟涓旇兘澶熻鍝﹀唴闃佸埗鍚勮繘绋嬬殑璧勬簮鍒嗛厤銆?/span>
鍦↙XC鐨勫熀纭€涔嬩笂锛宒ocker鎻愪緵浜嗕竴绯诲垪鏇村己澶х殑鍔熻兘銆?/span>
3銆佷粈涔堟槸docker
docker鏄竴涓紑婧愮殑搴旂敤瀹瑰櫒寮曟搸锛屽熀浜巊o璇█寮€鍙戝苟閬靛惊浜哸pache2.0鍗忚寮€婧愩€?/span>
docker鍙互璁╁紑鍙戣€呮墦鍖呬粬浠殑搴旂敤浠ュ強渚濊禆鍖呭埌涓€涓交閲忕骇銆佸彲绉绘鐨勫鍣ㄤ腑锛岀劧鍚庡彂甯冨埌浠讳綍娴佽鐨刲inux鏈嶅姟鍣紝涔熷彲浠ュ疄鐜拌櫄鎷熷寲銆?/span>
瀹瑰櫒鏄畬鍏ㄤ娇鐢ㄦ矙绠辨満鍒讹紝鐩镐簰涔嬮棿涓嶄細鏈変换浣曟帴鍙o紙绫籭phone鐨刟pp锛夛紝骞朵笖瀹瑰櫒寮€閿€鏋佸叾浣庛€?/span>
4銆乨ocker瀹樻柟鏂囨。
https://docs.docker.com/
5銆佷负浠€涔坉ocker瓒婃潵瓒婂彈娆㈣繋
瀹樻柟璇濊锛?/span>
瀹瑰櫒鍖栬秺鏉ヨ秺鍙楁杩庯紝鍥犱负瀹瑰櫒鏄細
鐏垫椿锛氬嵆浣挎槸鏈€澶嶆潅鐨勫簲鐢ㄤ篃鍙互闆嗚绠卞寲銆?/span>
杞婚噺绾э細瀹瑰櫒鍒╃敤骞跺叡浜富鏈哄唴鏍搞€?/span>
鍙簰鎹細鎮ㄥ彲浠ュ嵆鏃堕儴缃叉洿鏂板拰鍗囩骇銆?/span>
渚挎惡寮忥細鎮ㄥ彲浠ュ湪鏈湴鏋勫缓锛岄儴缃插埌浜戯紝骞跺湪浠讳綍鍦版柟杩愯銆?/span>
鍙墿灞曪細鎮ㄥ彲浠ュ鍔犲苟鑷姩鍒嗗彂瀹瑰櫒鍓湰銆?/span>
鍙爢鍙狅細鎮ㄥ彲浠ュ瀭鐩村拰鍗虫椂鍫嗗彔鏈嶅姟銆?/span>
闀滃儚鍜屽鍣紙contalners锛?/span>
閫氳繃闀滃儚鍚姩涓€涓鍣紝涓€涓暅鍍忔槸涓€涓彲鎵ц鐨勫寘锛屽叾涓寘鎷繍琛屽簲鐢ㄧ▼搴忔墍闇€瑕佺殑鎵€鏈夊唴瀹瑰寘鍚唬鐮侊紝杩愯鏃堕棿锛屽簱銆佺幆澧冨彉閲忋€佸拰閰嶇疆鏂囦欢銆?/span>
瀹瑰櫒鏄暅鍍忕殑杩愯瀹炰緥锛屽綋琚繍琛屾椂鏈夐暅鍍忕姸鎬佸拰鐢ㄦ埛杩涚▼锛屽彲浠ヤ娇鐢╠ocker ps 鏌ョ湅銆?/span>
瀹瑰櫒鍜岃櫄鎷熸満
瀹瑰櫒鏃跺湪linux涓婃湰鏈鸿繍琛岋紝骞朵笌鍏朵粬瀹瑰櫒鍏变韩涓绘満鐨勫唴鏍革紝瀹冭繍琛岀殑涓€涓嫭绔嬬殑杩涚▼锛屼笉鍗犵敤鍏朵粬浠讳綍鍙墽琛屾枃浠剁殑鍐呭瓨锛岄潪甯歌交閲忋€?/span>
铏氭嫙鏈鸿繍琛岀殑鏄竴涓畬鎴愮殑鎿嶄綔绯荤粺锛岄€氳繃铏氭嫙鏈虹鐞嗙▼搴忓涓绘満璧勬簮杩涜铏氭嫙璁块棶锛岀浉姣斾箣涓嬮渶瑕佺殑璧勬簮鏇村銆?/span>
6銆乨ocker鐗堟湰
Docker Community Edition锛圕E锛夌ぞ鍖虹増
Enterprise Edition(EE) 鍟嗕笟鐗?/span>
7銆乨ocker鍜宱penstack鐨勫嚑椤瑰姣?/span>
8銆佸鍣ㄥ湪鍐呮牳涓敮鎸?绉嶉噸瑕佹妧鏈?/span>
docker鏈川灏辨槸瀹夸富鏈虹殑涓€涓繘绋嬶紝docker鏄€氳繃namespace瀹炵幇璧勬簮闅旂锛岄€氳繃cgroup瀹炵幇璧勬簮闄愬埗锛岄€氳繃鍐欐椂澶嶅埗鎶€鏈紙copy-on-write锛夊疄鐜颁簡楂樻晥鐨勬枃浠舵搷浣滐紙绫讳技铏氭嫙鏈虹殑纾佺洏姣斿鍒嗛厤500g骞朵笉鏄疄闄呭崰鐢ㄧ墿鐞嗙鐩?00g锛?/span>
1锛塶amespaces 鍚嶇О绌洪棿
2锛塩ontrol Group 鎺у埗缁?/span>
cgroup鐨勭壒鐐规槸锛氥€€
銆€銆€銆€銆€銆€
cgroup鐨刟pi浠ヤ竴涓吉鏂囦欢绯荤粺鐨勫疄鐜版柟寮忥紝鐢ㄦ埛鐨勭▼搴忓彲浠ラ€氳繃鏂囦欢绯荤粺瀹炵幇cgroup鐨勭粍浠剁鐞?/span>
cgroup鐨勭粍浠剁鐞嗘搷浣滃崟鍏冨彲浠ョ粏绮掑害鍒扮嚎绋嬬骇鍒紝鍙﹀鐢ㄦ埛鍙互鍒涘缓鍜岄攢姣乧group锛屼粠鑰屽疄鐜拌祫婧愯浇鍒嗛厤鍜屽啀鍒╃敤
鎵€鏈夎祫婧愮鐞嗙殑鍔熻兘閮戒互瀛愮郴缁熺殑鏂瑰紡瀹炵幇锛屾帴鍙g粺涓€瀛愪换鍔″垱寤轰箣鍒濅笌鍏剁埗浠诲姟澶勪簬鍚屼竴涓猚group鐨勬帶鍒剁粍
鍥涘ぇ鍔熻兘锛?/span>
璧勬簮闄愬埗锛氬彲浠ュ浠诲姟浣跨敤鐨勮祫婧愭€婚杩涜闄愬埗
浼樺厛绾у垎閰嶏細閫氳繃鍒嗛厤鐨刢pu鏃堕棿鐗囨暟閲忎互鍙婄鐩業O甯﹀澶у皬锛屽疄闄呬笂鐩稿綋浜庢帶鍒朵簡浠诲姟杩愯浼樺厛绾?/span>
璧勬簮缁熻锛氬彲浠ョ粺璁$郴缁熺殑璧勬簮浣跨敤閲忥紝濡俢pu鏃堕暱锛屽唴瀛樼敤閲忕瓑
浠诲姟鎺у埗锛歝group鍙互瀵逛换鍔℃墽琛屾寕璧枫€佹仮澶嶇瓑鎿嶄綔
9銆佷簡瑙ocker涓変釜閲嶈姒傚康
1锛塱mage闀滃儚
docker闀滃儚灏辨槸涓€涓彧璇绘ā鏉匡紝姣斿锛屼竴涓暅鍍忓彲浠ュ寘鍚竴涓畬鏁寸殑centos锛岄噷闈粎瀹夎apache鎴栫敤鎴风殑鍏朵粬搴旂敤锛岄暅鍍忓彲浠ョ敤鏉ュ垱寤篸ocker瀹瑰櫒锛屽彟澶杁ocker鎻愪緵浜嗕竴涓緢绠€鍗曠殑鏈哄埗鏉ュ垱寤洪暅鍍忔垨鑰呮洿鏂扮幇鏈夌殑闀滃儚锛岀敤鎴风敋鑷冲彲浠ョ洿鎺ヤ粠鍏朵粬浜洪偅閲屼笅鍛ㄤ竴涓凡缁忓仛濂界殑闀滃儚鏉ョ洿鎺ヤ娇鐢?/span>
2锛塩ontainer瀹瑰櫒
docker鍒╃敤瀹瑰櫒鏉ヨ繍琛屽簲鐢紝瀹瑰櫒鏄粠闀滃儚鍒涘缓鐨勮繍琛屽疄渚嬶紝瀹冨彲浠ヨ鍚姩锛屽紑濮嬨€佸仠姝€佸垹闄ゃ€佹瘡涓鍣ㄩ兘鏄簰鐩搁殧绂荤殑锛屼繚璇佸畨鍏ㄧ殑骞冲彴锛屽彲浠ュ惂瀹瑰櫒鐪嬪仛鏄缁欑畝鏄撶増鐨刲inux鐜锛堝寘鎷瑀oot鐢ㄦ埛鏉冮檺銆侀暅鍍忕┖闂淬€佺敤鎴风┖闂村拰缃戠粶绌洪棿绛夛級鍜岃繍琛屽啀鍏朵腑鐨勫簲鐢ㄧ▼搴?/span>
3锛塺epostory浠撳簱
浠撳簱鏄泦涓瓨鍌ㄩ暅鍍忔枃浠剁殑娌ф锛宺egistry鏄粨搴撲富浠庢湇鍔″櫒锛屽疄闄呬笂鍙傝€冩敞鍐屾湇鍔″櫒涓婂瓨鏀剧潃澶氫釜浠撳簱锛屾瘡涓粨搴撲腑鍙堝寘鍚簡澶氫釜闀滃儚锛屾瘡涓暅鍍忔湁涓嶅悓鐨勬爣绛撅紙tag锛?/span>
浠撳簱鍒嗕负涓ょ锛屽叕鏈夊弬鑰冿紝鍜岀鏈変粨搴擄紝鏈€澶х殑鍏紑浠撳簱鏄痙ocker Hub锛屽瓨鏀句簡鏁伴噺搴炲ぇ鐨勯暅鍍忎緵鐢ㄦ埛涓嬪懆锛屽浗鍐呯殑docker pool锛岃繖閲屼粨搴撶殑姒傚康涓嶨it绫讳技锛宺egistry鍙互鐞嗚В涓篻ithub杩欐牱鐨勬墭绠℃湇鍔°€?/span>
10銆乨ocker鐨勪富瑕佺敤閫?/span>
瀹樻柟灏辨槸Bulid 銆乻hip銆乺un any app/any where锛岀紪璇戙€佽杞姐€佽繍琛屻€佷换浣昦pp/鍦ㄤ换鎰忓湴鏀鹃兘鑳借繍琛屻€?/span>
灏辨槸瀹炵幇浜嗗簲鐢ㄧ殑灏佽銆侀儴缃层€佽繍琛岀殑鐢熷懡鍛ㄦ湡绠$悊鍙鍦╣libc鐨勭幆澧冧笅锛岄兘鍙互杩愯銆?/span>
杩愮淮鐢熸垚鐜涓細docker鍖栥€?/span>
鍙戝竷鏈嶅姟涓嶇敤鎷呭績鏈嶅姟鍣ㄧ殑杩愯鐜锛屾墍鏈夌殑鏈嶅姟鍣ㄩ兘鏄嚜鍔ㄥ垎閰峝ocker锛岃嚜鍔ㄩ儴缃诧紝鑷姩瀹夎锛岃嚜鍔ㄨ繍琛?/span>
鍐嶄笉鐢ㄦ媴蹇冨叾浠栨湇鍔″紩鎿庣殑纾佺洏闂锛宑pu闂锛岀郴缁熼棶棰樹簡
璧勬簮鍒╃敤鏇村嚭鑹?/span>
鑷姩杩佺Щ锛屽彲浠ュ埗浣滈暅鍍忥紝杩佺Щ浣跨敤鑷畾涔夌殑闀滃儚鍗冲彲杩佺Щ锛屼笉浼氬嚭鐜颁粈涔堥棶棰?/span>
绠$悊鏇村姞鏂逛究浜?/span>
11銆乨ocker鏀瑰彉浜嗕粈涔?/span>
闈㈠悜浜у搧锛氫骇鍝佷氦浠?/span>
闈㈠悜寮€鍙戯細绠€鍖栫幆澧冮厤缃?/span>
闈㈠悜娴嬭瘯锛氬鐗堟湰娴嬭瘯
闈㈠悜杩愮淮锛氱幆澧冧竴鑷存€?/span>
闈㈠悜鏋舵瀯锛氳嚜鍔ㄥ寲鎵╁锛堝井鏈嶅姟锛?/span>
浜屻€乨ocker鏋舵瀯
1銆佹€讳綋鏋舵瀯
distribution 璐熻矗涓巇ocker registry浜や簰锛屼笂浼犳礂婢¢暅鍍忎互鍙妚2 registry 鏈夊叧鐨勬簮鏁版嵁
registry璐熻矗docker registry鏈夊叧鐨勮韩浠借璇併€侀暅鍍忔煡鎵俱€侀暅鍍忛獙璇佷互鍙婄鐞唕egistry mirror绛変氦浜掓搷浣?/span>
image 璐熻矗涓庨暅鍍忔簮鏁版嵁鏈夊叧鐨勫瓨鍌ㄣ€佹煡鎵撅紝闀滃儚灞傜殑绱㈠紩銆佹煡鎵句互鍙婇暅鍍弔ar鍖呮湁鍏崇殑瀵煎叆銆佸鍑烘搷浣?/span>
reference璐熻矗瀛樺偍鏈湴鎵€鏈夐暅鍍忕殑repository鍜宼ag鍚嶏紝骞剁淮鎶や笌闀滃儚id涔嬮棿鐨勬槧灏勫叧绯?/span>
layer妯″潡璐熻矗涓庨暅鍍忓眰鍜屽鍣ㄥ眰婧愭暟鎹湁鍏崇殑澧炲垹鏀规煡锛屽苟璐熻矗灏嗛暅鍍忓眰鐨勫鍒犳敼鏌ユ槧灏勫埌瀹為檯瀛樺偍闀滃儚灞傛枃浠剁殑graphdriver妯″潡
graghdriver鏄墍鏈変笌瀹瑰櫒闀滃儚鐩稿叧鎿嶄綔鐨勬墽琛岃€?/span>
2銆乨ocker鏋舵瀯2
濡傛灉瑙夊緱涓婇潰鏋舵瀯鍥炬瘮杈冧贡鍙互鐪嬭繖涓灦鏋勶細
浠庝笂鍥句笉闅剧湅鍑猴紝鐢ㄦ埛鏄娇鐢―ocker Client涓嶥ocker Daemon寤虹珛閫氫俊锛屽苟鍙戦€佽姹傜粰鍚庤€呫€?/span>
鑰孌ocker Daemon浣滀负Docker鏋舵瀯涓殑涓讳綋閮ㄥ垎锛岄鍏堟彁渚汼erver鐨勫姛鑳戒娇鍏跺彲浠ユ帴鍙桪ocker Client鐨勮姹傦紱鑰屽悗Engine鎵цDocker鍐呴儴鐨勪竴绯诲垪宸ヤ綔锛屾瘡涓€椤瑰伐浣滈兘鏄互涓€涓狫ob鐨勫舰寮忕殑瀛樺湪銆?/span>
Job鐨勮繍琛岃繃绋嬩腑锛屽綋闇€瑕佸鍣ㄩ暅鍍忔椂锛屽垯浠嶥ocker Registry涓笅杞介暅鍍忥紝骞堕€氳繃闀滃儚绠$悊椹卞姩graphdriver灏嗕笅杞介暅鍍忎互Graph鐨勫舰寮忓瓨鍌紱褰撻渶瑕佷负Docker鍒涘缓缃戠粶鐜鏃讹紝閫氳繃缃戠粶绠$悊椹卞姩networkdriver鍒涘缓骞堕厤缃瓺ocker瀹瑰櫒缃戠粶鐜锛涘綋闇€瑕侀檺鍒禗ocker瀹瑰櫒杩愯璧勬簮鎴栨墽琛岀敤鎴锋寚浠ょ瓑鎿嶄綔鏃讹紝鍒欓€氳繃execdriver鏉ュ畬鎴愩€?/span>
鑰宭ibcontainer鏄竴椤圭嫭绔嬬殑瀹瑰櫒绠$悊鍖咃紝networkdriver浠ュ強execdriver閮芥槸閫氳繃libcontainer鏉ュ疄鐜板叿浣撳瀹瑰櫒杩涜鐨勬搷浣溿€傚綋鎵ц瀹岃繍琛屽鍣ㄧ殑鍛戒护鍚庯紝涓€涓疄闄呯殑Docker瀹瑰櫒灏卞浜庤繍琛岀姸鎬侊紝璇ュ鍣ㄦ嫢鏈夌嫭绔嬬殑鏂囦欢绯荤粺锛岀嫭绔嬪苟涓斿畨鍏ㄧ殑杩愯鐜绛夈€?/span>
3銆乨ocker鏋舵瀯3
鍐嶆潵鐪嬬湅鍙﹀涓€涓灦鏋勶紝杩欎釜涓灦鏋勫氨绠€鍗曟竻鏅版寚鏄庝簡server/client浜や簰锛屽鍣ㄥ拰闀滃儚銆佹暟鎹箣闂寸殑涓€浜涜仈绯汇€?/span>
杩欎釜鏋舵瀯鍥炬洿鍔犳竻鏅颁簡鏋舵瀯
docker daemon灏辨槸docker鐨勫畧鎶よ繘绋嬪嵆server绔紝鍙互鏄繙绋嬬殑锛屼篃鍙互鏄湰鍦扮殑锛岃繖涓笉鏄疌/S鏋舵瀯鍚楋紝瀹㈡埛绔疍ocker client 鏄€氳繃rest api杩涜閫氫俊銆?/span>
docker cli 鐢ㄦ潵绠$悊瀹瑰櫒鍜岄暅鍍忥紝瀹㈡埛绔彁渚涗竴涓彧璇婚暅鍍忥紝鐒跺悗閫氳繃闀滃儚鍙互鍒涘缓澶氫釜瀹瑰櫒锛岃繖浜涘鍣ㄥ彲浠ュ彧鏄竴涓猂FS锛圧oot file system鏍规枃浠剁郴缁燂級锛屼篃鍙互ishi涓€涓寘鍚簡鐢ㄦ埛搴旂敤鐨凴FS锛屽鍣ㄥ啀docker client涓彧鏄缁欒繘绋嬶紝涓や釜杩涚▼涔嬮棿浜掍笉鍙銆?/span>
鐢ㄦ埛涓嶈兘涓巗erver鐩存帴浜や簰锛屼絾鍙互閫氳繃涓庡鍣ㄨ繖涓ˉ姊佹潵浜や簰锛岀敱浜庢槸鎿嶄綔绯荤粺绾у埆鐨勮櫄鎷熸妧鏈紝涓棿鐨勬崯鑰楀嚑涔庡彲浠ヤ笉璁°€?/span>
涓夈€乨ocker鏋舵瀯2鍚勪釜妯″潡鐨勫姛鑳斤紙甯﹀畬鍠勶級
涓昏鐨勬ā鍧楁湁锛欴ocker Client銆丏ocker Daemon銆丏ocker Registry銆丟raph銆丏river銆乴ibcontainer浠ュ強Docker container銆傘€€銆€銆€
1銆乨ocker client
docker client 鏄痙ocker鏋舵瀯涓敤鎴风敤鏉ュ拰docker daemon寤虹珛閫氫俊鐨勫鎴风锛岀敤鎴蜂娇鐢ㄧ殑鍙墽琛屾枃浠朵负docker锛岄€氳繃docker鍛戒护琛屽伐鍏峰彲浠ュ彂璧蜂紬澶氱鐞哻ontainer鐨勮姹傘€?/span>
docker client鍙互閫氳繃涓€涓嬩笁瀹楁柟寮忓拰docker daemon寤虹珛閫氫俊锛歵cp://host:port;unix:path_to_socket;fd://socketfd銆傦紝docker client鍙互閫氳繃璁剧疆鍛戒护琛宖lag鍙傛暟鐨勫舰寮忚缃畨鍏ㄤ紶杈撳眰鍗忚(TLS)鐨勬湁鍏冲弬鏁帮紝淇濊瘉浼犺緭鐨勫畨鍏ㄦ€с€?/span>
docker client鍙戦€佸鍣ㄧ鐞嗚姹傚悗锛岀敱docker daemon鎺ュ彈骞跺鐞嗚姹傦紝褰揹ocker client 鎺ユ敹鍒拌繑鍥炵殑璇锋眰鐩稿簲骞剁畝鍗曞鐞嗗悗锛宒ocker client 涓€娆″畬鏁寸殑鐢熷懡鍛ㄦ湡灏辩粨鏉熶簡锛屽綋闇€瑕佺户缁彂閫佸鍣ㄧ鐞嗚姹傛椂锛岀敤鎴峰繀椤诲啀娆¢€氳繃docker鍙互鎵ц鏂囦欢鍒涘缓docker client銆?/span>
2銆乨ocker daemon
docker daemon 鏄痙ocker鏋舵瀯涓竴涓父椹诲湪鍚庡彴鐨勭郴缁熻繘绋嬶紝鍔熻兘鏄細鎺ユ敹澶勭悊docker client鍙戦€佺殑璇锋眰銆傝瀹堟姢杩涚▼鍦ㄥ悗鍙板惎鍔ㄤ竴涓猻erver锛宻erver璐熻浇鎺ュ彈docker client鍙戦€佺殑璇锋眰锛涙帴鍙楄姹傚悗锛宻erver閫氳繃璺敱涓庡垎鍙戣皟搴︼紝鎵惧埌鐩稿簲鐨刪andler鏉ユ墽琛岃姹傘€?/span>
docker daemon鍚姩鎵€浣跨敤鐨勫彲鎵ц鏂囦欢涔熶负docker锛屼笌docker client鍚姩鎵€浣跨敤鐨勫彲鎵ц鏂囦欢docker鐩稿悓锛屽湪docker鍛戒护鎵ц鏃讹紝閫氳繃浼犲叆鐨勫弬鏁版潵鍒ゅ埆docker daemon涓巇ocker client銆?/span>
docker daemon鐨勬灦鏋勫彲浠ュ垎涓猴細docker server銆乪ngine銆乯ob銆俤aemon
3銆乨ocker server
docker server鍦╠ocker鏋舵瀯涓椂涓撻棬鏈嶅姟浜巇ocker client鐨剆erver锛岃server鐨勫姛鑳芥椂锛氭帴鍙楀苟璋冨害鍒嗗彂docker client鍙戦€佺殑璇锋眰锛屾灦鏋勫浘濡備笅锛?/span>
銆€銆€銆€
鍦―ocker鐨勫惎鍔ㄨ繃绋嬩腑锛岄€氳繃鍖単orilla/mux锛坓olang鐨勭被搴撹В鏋愶級锛屽垱寤轰簡涓€涓猰ux.Router锛屾彁渚涜姹傜殑璺敱鍔熻兘銆傚湪Golang涓紝gorilla/mux鏄竴涓己澶х殑URL璺敱鍣ㄤ互鍙婅皟搴﹀垎鍙戝櫒銆傝mux.Router涓坊鍔犱簡浼楀鐨勮矾鐢遍」锛屾瘡涓€涓矾鐢遍」鐢盚TTP璇锋眰鏂规硶锛圥UT銆丳OST銆丟ET鎴朌ELETE锛夈€乁RL銆丠andler涓夐儴鍒嗙粍鎴愩€?/span>
鍦⊿erver鐨勬湇鍔¤繃绋嬩腑锛孲erver鍦╨istener涓婃帴鍙桪ocker Client鐨勮闂姹傦紝骞跺垱寤轰竴涓叏鏂扮殑goroutine鏉ユ湇鍔¤璇锋眰銆傚湪goroutine涓紝棣栧厛璇诲彇璇锋眰鍐呭锛岀劧鍚庡仛瑙f瀽宸ヤ綔锛屾帴鐫€鎵惧埌鐩稿簲鐨勮矾鐢遍」锛岄殢鍚庤皟鐢ㄧ浉搴旂殑Handler鏉ュ鐞嗚璇锋眰锛屾渶鍚嶩andler澶勭悊瀹岃姹備箣鍚庡洖澶嶈璇锋眰銆?/span>
闇€瑕佹敞鎰忕殑鏄細Docker Server鐨勮繍琛屽湪Docker鐨勫惎鍔ㄨ繃绋嬩腑锛屾槸闈犱竴涓悕涓衡€漵erveapi鈥濈殑job鐨勮繍琛屾潵瀹屾垚鐨勩€傚師鍒欎笂锛孌ocker Server鐨勮繍琛屾槸浼楀job涓殑涓€涓紝浣嗘槸涓轰簡寮鸿皟Docker Server鐨勯噸瑕佹€т互鍙婁负鍚庣画job鏈嶅姟鐨勯噸瑕佺壒鎬э紝灏嗚鈥漵erveapi鈥濈殑job鍗曠嫭鎶界鍑烘潵鍒嗘瀽锛岀悊瑙d负Docker Server銆?/span>
4銆乪ngine
Engine鏄疍ocker鏋舵瀯涓殑杩愯寮曟搸锛屽悓鏃朵篃Docker杩愯鐨勬牳蹇冩ā鍧椼€傚畠鎵紨Docker container瀛樺偍浠撳簱鐨勮鑹诧紝骞朵笖閫氳繃鎵цjob鐨勬柟寮忔潵鎿嶇旱绠$悊杩欎簺瀹瑰櫒銆?/span>
鍦‥ngine鏁版嵁缁撴瀯鐨勮璁′笌瀹炵幇杩囩▼涓紝鏈変竴涓猦andler瀵硅薄銆傝handler瀵硅薄瀛樺偍鐨勯兘鏄叧浜庝紬澶氱壒瀹歫ob鐨刪andler澶勭悊璁块棶銆備妇渚嬭鏄庯紝Engine鐨刪andler瀵硅薄涓湁涓€椤逛负锛歿鈥渃reate鈥? daemon.ContainerCreate,}锛屽垯璇存槑褰撳悕涓衡€漜reate鈥濈殑job鍦ㄨ繍琛屾椂锛屾墽琛岀殑鏄痙aemon.ContainerCreate鐨刪andler銆?/span>
5銆乯ob
涓€涓狫ob鍙互璁や负鏄疍ocker鏋舵瀯涓璄ngine鍐呴儴鏈€鍩烘湰鐨勫伐浣滄墽琛屽崟鍏冦€侱ocker鍙互鍋氱殑姣忎竴椤瑰伐浣滐紝閮藉彲浠ユ娊璞′负涓€涓猨ob銆備緥濡傦細鍦ㄥ鍣ㄥ唴閮ㄨ繍琛屼竴涓繘绋嬶紝杩欐槸涓€涓猨ob锛涘垱寤轰竴涓柊鐨勫鍣紝杩欐槸涓€涓猨ob锛屼粠Internet涓婁笅杞戒竴涓枃妗o紝杩欐槸涓€涓猨ob锛涘寘鎷箣鍓嶅湪Docker Server閮ㄥ垎璇磋繃鐨勶紝鍒涘缓Server鏈嶅姟浜嶩TTP鐨凙PI锛岃繖涔熸槸涓€涓猨ob锛岀瓑绛夈€?/span>
Job鐨勮璁¤€咃紝鎶奐ob璁捐寰椾笌Unix杩涚▼鐩镐豢銆傛瘮濡傝锛欽ob鏈変竴涓悕绉帮紝鏈夊弬鏁帮紝鏈夌幆澧冨彉閲忥紝鏈夋爣鍑嗙殑杈撳叆杈撳嚭锛屾湁閿欒澶勭悊锛屾湁杩斿洖鐘舵€佺瓑銆?/span>
6銆乨ocker registry
Docker Registry鏄竴涓瓨鍌ㄥ鍣ㄩ暅鍍忕殑浠撳簱銆傝€屽鍣ㄩ暅鍍忔槸鍦ㄥ鍣ㄨ鍒涘缓鏃讹紝琚姞杞界敤鏉ュ垵濮嬪寲瀹瑰櫒鐨勬枃浠舵灦鏋勪笌鐩綍銆?/span>
鍦―ocker鐨勮繍琛岃繃绋嬩腑锛孌ocker Daemon浼氫笌Docker Registry閫氫俊锛屽苟瀹炵幇鎼滅储闀滃儚銆佷笅杞介暅鍍忋€佷笂浼犻暅鍍忎笁涓姛鑳斤紝杩欎笁涓姛鑳藉搴旂殑job鍚嶇О鍒嗗埆涓衡€漵earch鈥濓紝鈥漰ull鈥?涓?鈥減ush鈥濄€?/span>
鍏朵腑锛屽湪Docker鏋舵瀯涓紝Docker鍙互浣跨敤鍏湁鐨凞ocker Registry锛屽嵆澶у鐔熺煡鐨凞ocker Hub锛屽姝や竴鏉ワ紝Docker鑾峰彇瀹瑰櫒闀滃儚鏂囦欢鏃讹紝蹇呴』閫氳繃浜掕仈缃戣闂瓺ocker Hub锛涘悓鏃禗ocker涔熷厑璁哥敤鎴锋瀯寤烘湰鍦扮鏈夌殑Docker Registry锛岃繖鏍峰彲浠ヤ繚璇佸鍣ㄩ暅鍍忕殑鑾峰彇鍦ㄥ唴缃戝畬鎴愩€?/span>
7銆丟raph
Graph鍦―ocker鏋舵瀯涓壆婕斿凡涓嬭浇瀹瑰櫒闀滃儚鐨勪繚绠¤€咃紝浠ュ強宸蹭笅杞藉鍣ㄩ暅鍍忎箣闂村叧绯荤殑璁板綍鑰呫€備竴鏂归潰锛孏raph瀛樺偍鐫€鏈湴鍏锋湁鐗堟湰淇℃伅鐨勬枃浠剁郴缁熼暅鍍忥紝鍙︿竴鏂归潰涔熼€氳繃GraphDB璁板綍鐫€鎵€鏈夋枃浠剁郴缁熼暅鍍忓郊姝や箣闂寸殑鍏崇郴銆?/span>
Graph鐨勬灦鏋勫涓嬶細
鍏朵腑锛孏raphDB鏄竴涓瀯寤哄湪SQLite涔嬩笂鐨勫皬鍨嬪浘鏁版嵁搴擄紝瀹炵幇浜嗚妭鐐圭殑鍛藉悕浠ュ強鑺傜偣涔嬮棿鍏宠仈鍏崇郴鐨勮褰曘€傚畠浠呬粎瀹炵幇浜嗗ぇ澶氭暟鍥炬暟鎹簱鎵€鎷ユ湁鐨勪竴涓皬鐨勫瓙闆嗭紝浣嗘槸鎻愪緵浜嗙畝鍗曠殑鎺ュ彛琛ㄧず鑺傜偣涔嬮棿鐨勫叧绯汇€?/span>
鍚屾椂鍦℅raph鐨勬湰鍦扮洰褰曚腑锛屽叧浜庢瘡涓€涓殑瀹瑰櫒闀滃儚锛屽叿浣撳瓨鍌ㄧ殑淇℃伅鏈夛細璇ュ鍣ㄩ暅鍍忕殑鍏冩暟鎹紝瀹瑰櫒闀滃儚鐨勫ぇ灏忎俊鎭紝浠ュ強璇ュ鍣ㄩ暅鍍忔墍浠h〃鐨勫叿浣搑ootfs銆?/span>
8銆乨river
Driver鏄疍ocker鏋舵瀯涓殑椹卞姩妯″潡銆傞€氳繃Driver椹卞姩锛孌ocker鍙互瀹炵幇瀵笵ocker瀹瑰櫒鎵ц鐜鐨勫畾鍒躲€傜敱浜嶥ocker杩愯鐨勭敓鍛藉懆鏈熶腑锛屽苟闈炵敤鎴锋墍鏈夌殑鎿嶄綔閮芥槸閽堝Docker瀹瑰櫒鐨勭鐞嗭紝鍙﹀杩樻湁鍏充簬Docker杩愯淇℃伅鐨勮幏鍙栵紝Graph鐨勫瓨鍌ㄤ笌璁板綍绛夈€傚洜姝わ紝涓轰簡灏咲ocker瀹瑰櫒鐨勭鐞嗕粠Docker Daemon鍐呴儴涓氬姟閫昏緫涓尯鍒嗗紑鏉ワ紝璁捐浜咲river灞傞┍鍔ㄦ潵鎺ョ鎵€鏈夎繖閮ㄥ垎璇锋眰銆?/span>
鍦―ocker Driver鐨勫疄鐜颁腑锛屽彲浠ュ垎涓轰互涓嬩笁绫婚┍鍔細graphdriver銆乶etworkdriver鍜宔xecdriver銆?/span>
graphdriver涓昏鐢ㄤ簬瀹屾垚瀹瑰櫒闀滃儚鐨勭鐞嗭紝鍖呮嫭瀛樺偍涓庤幏鍙栥€傚嵆褰撶敤鎴烽渶瑕佷笅杞芥寚瀹氱殑瀹瑰櫒闀滃儚鏃讹紝graphdriver灏嗗鍣ㄩ暅鍍忓瓨鍌ㄥ湪鏈湴鐨勬寚瀹氱洰褰曪紱鍚屾椂褰撶敤鎴烽渶瑕佷娇鐢ㄦ寚瀹氱殑瀹瑰櫒闀滃儚鏉ュ垱寤哄鍣ㄧ殑rootfs鏃讹紝graphdriver浠庢湰鍦伴暅鍍忓瓨鍌ㄧ洰褰曚腑鑾峰彇鎸囧畾鐨勫鍣ㄩ暅鍍忋€?/span>
鍦╣raphdriver鐨勫垵濮嬪寲杩囩▼涔嬪墠锛屾湁4绉嶆枃浠剁郴缁熸垨绫绘枃浠剁郴缁熷湪鍏跺唴閮ㄦ敞鍐岋紝瀹冧滑鍒嗗埆鏄痑ufs銆乥trfs銆乿fs鍜宒evmapper銆傝€孌ocker鍦ㄥ垵濮嬪寲涔嬫椂锛岄€氳繃鑾峰彇绯荤粺鐜鍙橀噺鈥滵OCKER_DRIVER鈥濇潵鎻愬彇鎵€浣跨敤driver鐨勬寚瀹氱被鍨嬨€傝€屼箣鍚庢墍鏈夌殑graph鎿嶄綔锛岄兘浣跨敤璇river鏉ユ墽琛屻€?/span>
graphdriver鐨勬灦鏋勫涓嬶細
networkdriver鐨勭敤閫旀槸瀹屾垚Docker瀹瑰櫒缃戠粶鐜鐨勯厤缃紝鍏朵腑鍖呮嫭Docker鍚姩鏃朵负Docker鐜鍒涘缓缃戞ˉ锛汥ocker瀹瑰櫒鍒涘缓鏃朵负鍏跺垱寤轰笓灞炶櫄鎷熺綉鍗¤澶囷紱浠ュ強涓篋ocker瀹瑰櫒鍒嗛厤IP銆佺鍙e苟涓庡涓绘満鍋氱鍙f槧灏勶紝璁剧疆瀹瑰櫒闃茬伀澧欑瓥鐣ョ瓑銆俷etworkdriver鐨勬灦鏋勫涓嬶細
execdriver浣滀负Docker瀹瑰櫒鐨勬墽琛岄┍鍔紝璐熻矗鍒涘缓瀹瑰櫒杩愯鍛藉悕绌洪棿锛岃礋璐e鍣ㄨ祫婧愪娇鐢ㄧ殑缁熻涓庨檺鍒讹紝璐熻矗瀹瑰櫒鍐呴儴杩涚▼鐨勭湡姝h繍琛岀瓑銆傚湪execdriver鐨勫疄鐜拌繃绋嬩腑锛屽師鍏堝彲浠ヤ娇鐢↙XC椹卞姩璋冪敤LXC鐨勬帴鍙o紝鏉ユ搷绾靛鍣ㄧ殑閰嶇疆浠ュ強鐢熷懡鍛ㄦ湡锛岃€岀幇鍦╡xecdriver榛樿浣跨敤native椹卞姩锛屼笉渚濊禆浜嶭XC銆?/span>
鍏蜂綋浣撶幇鍦―aemon鍚姩杩囩▼涓姞杞界殑ExecDriverflag鍙傛暟锛岃鍙傛暟鍦ㄩ厤缃枃浠跺凡缁忚璁句负鈥漬ative鈥濄€傝繖鍙互璁や负鏄疍ocker鍦?.2鐗堟湰涓婁竴涓緢澶х殑鏀瑰彉锛屾垨鑰呰Docker瀹炵幇璺ㄥ钩鍙扮殑涓€涓厛鍏嗐€俥xecdriver鏋舵瀯濡備笅锛?/span>
9銆乴ibcontainer
libcontainer鏄疍ocker鏋舵瀯涓竴涓娇鐢℅o璇█璁捐瀹炵幇鐨勫簱锛岃璁″垵琛锋槸甯屾湜璇ュ簱鍙互涓嶄緷闈犱换浣曚緷璧栵紝鐩存帴璁块棶鍐呮牳涓笌瀹瑰櫒鐩稿叧鐨凙PI銆?/span>
姝f槸鐢变簬libcontainer鐨勫瓨鍦紝Docker鍙互鐩存帴璋冪敤libcontainer锛岃€屾渶缁堟搷绾靛鍣ㄧ殑namespace銆乧groups銆乤pparmor銆佺綉缁滆澶囦互鍙婇槻鐏瑙勫垯绛夈€傝繖涓€绯诲垪鎿嶄綔鐨勫畬鎴愰兘涓嶉渶瑕佷緷璧朙XC鎴栬€呭叾浠栧寘銆俵ibcontainer鏋舵瀯濡備笅锛?/span>
鍙﹀锛宭ibcontainer鎻愪緵浜嗕竴鏁村鏍囧噯鐨勬帴鍙f潵婊¤冻涓婂眰瀵瑰鍣ㄧ鐞嗙殑闇€姹傘€傛垨鑰呰锛宭ibcontainer灞忚斀浜咲ocker涓婂眰瀵瑰鍣ㄧ殑鐩存帴绠$悊銆傚張鐢变簬libcontainer浣跨敤Go杩欑璺ㄥ钩鍙扮殑璇█寮€鍙戝疄鐜帮紝涓旀湰韬張鍙互琚笂灞傚绉嶄笉鍚岀殑缂栫▼璇█璁块棶锛屽洜姝ゅ緢闅捐锛屾湭鏉ョ殑Docker灏变竴瀹氫細绱х揣鍦板拰Linux鎹嗙粦鍦ㄤ竴璧枫€傝€屼簬姝ゅ悓鏃讹紝Microsoft鍦ㄥ叾钁楀悕浜戣绠楀钩鍙癆zure涓紝涔熸坊鍔犱簡瀵笵ocker鐨勬敮鎸侊紝鍙Docker鐨勫紑鏀剧▼搴︿笌涓氱晫鐨勭伀鐑害銆?/span>
鏆備笉璋圖ocker锛岀敱浜巐ibcontainer鐨勫姛鑳戒互鍙婂叾鏈韩涓庣郴缁熺殑鏉捐€﹀悎鐗规€э紝寰堟湁鍙兘浼氬湪鍏朵粬浠ュ鍣ㄤ负鍘熷瀷鐨勫钩鍙板嚭鐜帮紝鍚屾椂涔熷緢鏈夊彲鑳藉偓鐢熷嚭浜戣绠楅鍩熷叏鏂扮殑椤圭洰銆?/span>
10銆乨ocker container
Docker container锛圖ocker瀹瑰櫒锛夋槸Docker鏋舵瀯涓湇鍔′氦浠樼殑鏈€缁堜綋鐜板舰寮忋€?/span>
Docker鎸夌収鐢ㄦ埛鐨勯渶姹備笌鎸囦护锛岃鍒剁浉搴旂殑Docker瀹瑰櫒锛?/span>
鐢ㄦ埛閫氳繃鎸囧畾瀹瑰櫒闀滃儚锛屼娇寰桪ocker瀹瑰櫒鍙互鑷畾涔塺ootfs绛夋枃浠剁郴缁燂紱
鐢ㄦ埛閫氳繃鎸囧畾璁$畻璧勬簮鐨勯厤棰濓紝浣垮緱Docker瀹瑰櫒浣跨敤鎸囧畾鐨勮绠楄祫婧愶紱
鐢ㄦ埛閫氳繃閰嶇疆缃戠粶鍙婂叾瀹夊叏绛栫暐锛屼娇寰桪ocker瀹瑰櫒鎷ユ湁鐙珛涓斿畨鍏ㄧ殑缃戠粶鐜锛?/span>
鐢ㄦ埛閫氳繃鎸囧畾杩愯鐨勫懡浠わ紝浣垮緱Docker瀹瑰櫒鎵ц鎸囧畾鐨勫伐浣溿€?/span>
鍥涖€乨ocker绠€鍗曚娇鐢?/span>
1銆佸畨瑁?/span>
yum install docker -y
systemctl enable docker
systemctl start docker
娉ㄦ剰锛氬惎鍔ㄥ墠搴斿綋璁剧疆婧?/span>
vim /usr/lib/systemd/system/docker.service
杩欓噷璁剧疆闃块噷鐨勶紝娉ㄥ唽闃块噷浜戣处鎴峰彿姣忎釜鐢ㄦ埛閮芥湁锛?/span>
[root@web1 ~]# vim /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target
Wants=docker-storage-setup.service
Requires=docker-cleanup.timer
[Service]
Type=notify
NotifyAccess=main
EnvironmentFile=-/run/containers/registries.conf
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current --registry-mirror=https://rfcod7oz.mirror.aliyuncs.com #杩欎釜鍊煎彲浠ョ櫥闄嗛樋閲屼簯璐﹀彿璇峰弬鑰冧笅鍥?/span>
--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current
--default-runtime=docker-runc
--exec-opt native.cgroupdriver=systemd
--userland-proxy-path=/usr/libexec/docker/docker-proxy-current
--init-path=/usr/libexec/docker/docker-init-current
--seccomp-profile=/etc/docker/seccomp.json
$OPTIONS
$DOCKER_STORAGE_OPTIONS
$DOCKER_NETWORK_OPTIONS
$ADD_REGISTRY
$BLOCK_REGISTRY
$INSECURE_REGISTRY
$REGISTRIES
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
KillMode=process
[Install]
WantedBy=multi-user.target
2銆乨ocker鐗堟湰鏌ヨ
[root@web1 ~]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version: docker-1.13.1-96.gitb2f74b2.el7.centos.x86_64
Go version: go1.10.3
Git commit: b2f74b2/1.13.1
Built: Wed May 1 14:55:20 2019
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: docker-1.13.1-96.gitb2f74b2.el7.centos.x86_64
Go version: go1.10.3
Git commit: b2f74b2/1.13.1
Built: Wed May 1 14:55:20 2019
OS/Arch: linux/amd64
Experimental: false
3銆佹悳绱笅杞介暅鍍?/span>
docker pull alpine銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€#涓嬭浇闀滃儚
docker search nginx銆€銆€銆€銆€銆€銆€銆€銆€銆€ #鏌ョ湅闀滃儚
docker pull nginx
4銆佹煡鐪嬪凡缁忎笅杞界殑闀滃儚
[root@web1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zxg/my_nginx v1 b164f4c07c64 8 days ago 126 MB
zxg/my_nginx latest f07837869dfc 8 days ago 126 MB
docker.io/nginx latest e445ab08b2be 2 weeks ago 126 MB
docker.io/alpine latest b7b28af77ffe 3 weeks ago 5.58 MB
docker.io/centos latest 9f38484d220f 4 months ago 202 MB
[root@web1 ~]#
5銆佸鍑洪暅鍍?/span>
docker save nginx >/tmp/nginx.tar.gz
6銆佸垹闄ら暅鍍?/span>
docker rmi -f nginx
7銆佸鍏ラ暅鍍?/span>
docker load </tmp/nginx.tar.gz
8銆侀粯璁ら厤缃枃浠?/span>
vim /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target
Wants=docker-storage-setup.service
Requires=docker-cleanup.timer
[Service]
Type=notify
NotifyAccess=main
EnvironmentFile=-/run/containers/registries.conf
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current --registry-mirror=https://rfcod7oz.mirror.aliyuncs.com
--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current
--default-runtime=docker-runc
--exec-opt native.cgroupdriver=systemd
--userland-proxy-path=/usr/libexec/docker/docker-proxy-current
--init-path=/usr/libexec/docker/docker-init-current
--seccomp-profile=/etc/docker/seccomp.json
$OPTIONS
$DOCKER_STORAGE_OPTIONS
$DOCKER_NETWORK_OPTIONS
$ADD_REGISTRY
$BLOCK_REGISTRY
$INSECURE_REGISTRY
$REGISTRIES
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
KillMode=process
[Install]
WantedBy=multi-user.target
~
~
~
~
濡傛灉鏇存敼瀛樺偍鐩綍灏辨坊鍔犮€€
--graph=/opt/docker
濡傛灉鏇存敼DNS鈥斺€旈粯璁ら噰鐢ㄥ涓绘満鐨刣ns
--dns=xxxx鐨勬柟寮忔寚瀹?/code>
9銆佽繍琛宧ello world
杩欓噷鐢╟entos闀滃儚echo涓€涓猦ello word
[root@web1 overlay2]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zxg/my_nginx v1 b164f4c07c64 8 days ago 126 MB
zxg/my_nginx latest f07837869dfc 8 days ago 126 MB
docker.io/nginx latest e445ab08b2be 2 weeks ago 126 MB
docker.io/alpine latest b7b28af77ffe 3 weeks ago 5.58 MB
docker.io/centos latest 9f38484d220f 4 months ago 202 MB
[root@web1 overlay2]# docker run centos echo "hello world"
hello world
[root@web1 overlay2]#
10銆佽繍琛屼竴涓鍣?run
[root@web1 overlay2]# docker run -it alpine sh #杩愯骞惰繘鍏lpine
/ #
/ #
/ #
/ #
/ #
/ # ls
bin etc lib mnt proc run srv tmp var
dev home media opt root sbin sys usr
/ # cd tmp
/tmp # exit
鍚庡彴杩愯锛?d鍚庡彴杩愯锛夛紙--name娣诲姞涓€涓悕瀛楋級
[root@web1 overlay2]# docker run -it -d --name test1 alpine
ac46c019b800d34c37d4f9dcd56c974cb82eca3acf185e5f8f80c8a60075e343
[root@web1 overlay2]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ac46c019b800 alpine "/bin/sh" 5 seconds ago Up 3 seconds test1
[root@web1 overlay2]#
杩樻湁涓€绉?rm鍙傛暟锛宑trl+c鍚庡氨鍒犻櫎锛屽彲浠ユ祴璇曠幆澧冪敤锛岀敓鎴愮幆澧冪敤鐨勫皯
[root@web1 overlay2]# docker run -it --rm --name centos nginx
^C[root@web1 overlay2]#
##鍙﹀紑涓€涓獥鍙?br>[root@web1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3397b96ea7bd nginx "nginx -g 'daemon ..." 27 seconds ago Up 25 seconds 80/tcp centos
ac46c019b800 alpine "/bin/sh" 4 minutes ago Up 4 minutes test1
[root@web1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ac46c019b800 alpine "/bin/sh" 4 minutes ago Up 4 minutes test1
[root@web1 ~]#
11銆佸浣曡繘鍏ュ鍣?/span>
涓夌鏂规硶锛屼笂闈㈠凡缁忔紨绀轰簡涓€绉?/span>
绗竴绉嶏紝闇€瑕佸鍣ㄦ湰韬殑pid鍙妘til-linux锛屼笉鎺ㄨ崘锛屾殏鏃朵笉婕旂ず浜?/span>
绗簩绉嶏紝涓嶅垎閰峛ash缁堢鐨勪竴绉嶅疄鏂芥搷浣滐紝涓嶆帹鑽愶紝杩欑鎿嶄綔濡傛灉鍦ㄥ紑涓€涓獥鍙d篃鑳界湅鍒版搷浣滅殑鎸囦护锛屾墍鏈変汉閮借兘鐪嬪埌銆?/span>
[root@web1 overlay2]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9fc796e928d7 nginx "sh" 2 minutes ago Up 8 seconds 80/tcp mynginx
ac46c019b800 alpine "/bin/sh" 12 minutes ago Up 12 minutes test1
[root@web1 overlay2]# docker attach mynginx
#
#
#
#
# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
# exit銆€銆€
[root@web1 overlay2]# docker attach mynginx
You cannot attach to a stopped container, start it first
[root@web1 overlay2]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ac46c019b800 alpine "/bin/sh" 13 minutes ago Up 13 minutes test1
[root@web1 overlay2]#
绗笁绉嶏細exec鏂瑰紡锛岀粓绔椂鍒嗗紑鐨勶紝鎺ㄨ崘
[root@web1 overlay2]# docker exec -it mynginx sh
#
#
#
# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
# exit
[root@web1 overlay2]#
[root@web1 overlay2]#
[root@web1 overlay2]#
[root@web1 overlay2]# docker pa
docker: 'pa' is not a docker command.
See 'docker --help'
[root@web1 overlay2]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6fc2d091cfe9 nginx "nginx -g 'daemon ..." 45 seconds ago Up 43 seconds 80/tcp mynginx
ac46c019b800 alpine "/bin/sh" 16 minutes ago Up 16 minutes test1
12銆佹煡鐪媎ocker杩涚▼鍙婂垹闄ゅ鍣?/span>
涓婇潰宸茬粡婕旂ず锛?/span>
[root@web1 overlay2]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9fc796e928d7 nginx "sh" 2 minutes ago Up 8 seconds 80/tcp mynginx
ac46c019b800 alpine "/bin/sh" 12 minutes ago Up 12 minutes test1
[root@web1 overlay2]# docker ps -a 銆€銆€銆€銆€銆€銆€#-a :鏄剧ず鎵€鏈夌殑瀹瑰櫒锛屽寘鎷湭杩愯鐨?/span>
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9fc796e928d7 nginx "sh" 4 minutes ago Exited (0) About a minute ago mynginx
ac46c019b800 alpine "/bin/sh" 15 minutes ago Up 15 minutes test1
3bf234febeaa alpine "sh" 17 minutes ago Exited (0) 16 minutes ago youthful_lumiere
ab113c63f0b4 centos "echo 'hello world'" 31 minutes ago Exited (0) 31 minutes ago infallible_torvalds
b326027dcf42 zxg/my_nginx "nginx" 8 days ago Exited (0) 8 days ago my_nginx
4f1f1ca319f2 centos "bash" 8 days ago Exited (137) 8 days ago musing_lichterman
64b4e32991c7 nginx "nginx -g 'daemon ..." 12 days ago Exited (0) 12 days ago mynginx1
aee506fe7b5a alpine "sh" 12 days ago Created infallible_haibt
70620c73b9a0 alpine "sh" 12 days ago Created gallant_volhard
7655cbf87bb0 alpine "sh" 12 days ago Created agitated_brahmagupta
33fb949372e8 fce289e99eb9 "/hello" 12 days ago Created elastic_dijkstra
9de47616aea4 fce289e99eb9 "/hello" 13 days ago Created confident_fermi
[root@web1 overlay2]# docker rm 9fc796e928d7 #rm鏃跺垹闄や竴涓垨澶氫釜瀹瑰櫒
9fc796e928d7
13銆佹煡鐪嬪鍣ㄨ缁嗕俊鎭?/span>
[root@web1 overlay2]# docker inspect mynginx
[
{
"Id": "6fc2d091cfe9b0484da3e70db842446bbdfeb7f5e5409c2e40ae21b99498d010",
"Created": "2019-08-07T08:57:48.864538933Z",
"Path": "nginx",
"Args": [
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 119948,
"ExitCode": 0,
"Error": "",
"StartedAt": "2019-08-07T08:57:49.417992182Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:e445ab08b2be8b178655b714f89e5db9504f67defd5c7408a00bade679a50d44",
"ResolvConfPath": "/var/lib/docker/containers/6fc2d091cfe9b0484da3e70db842446bbdfeb7f5e5409c2e40ae21b99498d010/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/6fc2d091cfe9b0484da3e70db842446bbdfeb7f5e5409c2e40ae21b99498d010/hostname",
"HostsPath": "/var/lib/docker/containers/6fc2d091cfe9b0484da3e70db842446bbdfeb7f5e5409c2e40ae21b99498d010/hosts",
"LogPath": "",
"Name": "/mynginx",
"RestartCount": 0,
"Driver": "overlay2",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "journald",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "docker-runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Name": "overlay2",
"Data": {
"LowerDir": "/var/lib/docker/overlay2/937140af0aee6c43f04c2d7b72e6b5451a44fef921417e8236d9fe01e9286c7a-init/diff:/var/lib/docker/overlay2/d8e95505fc3894eb30b48e4b0f48ab5e89d99c09a07c79c0b057c611621e31eb/diff:/var/lib/docker/overlay2/b2a6a25974bf17398b698a27208711574be3c69a2cd06658bbe838359f373a27/diff:/var/lib/docker/overlay2/d4610bc89b3ba8ad6ab30ea895fc3a06efff15db493d86ac9bc100e04abbab67/diff",
"MergedDir": "/var/lib/docker/overlay2/937140af0aee6c43f04c2d7b72e6b5451a44fef921417e8236d9fe01e9286c7a/merged",
"UpperDir": "/var/lib/docker/overlay2/937140af0aee6c43f04c2d7b72e6b5451a44fef921417e8236d9fe01e9286c7a/diff",
"WorkDir": "/var/lib/docker/overlay2/937140af0aee6c43f04c2d7b72e6b5451a44fef921417e8236d9fe01e9286c7a/work"
}
},
"Mounts": [],
"Config": {
"Hostname": "6fc2d091cfe9",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": true,
"OpenStdin": true,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.17.2",
"NJS_VERSION=0.3.3",
"PKG_RELEASE=1~buster"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"ArgsEscaped": true,
"Image": "nginx",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
},
"StopSignal": "SIGTERM"
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "3ece36008fbc5f3f46d3d251cf803c1478cc14032d74a36747e4ed8a115b81df",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": null
},
"SandboxKey": "/var/run/docker/netns/3ece36008fbc",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "898de81d97d54d2b60aeb6cc77ef1b4f9b481d1b72f542faa496494594024eac",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.3", 銆€銆€銆€銆€銆€銆€#鐪嬪埌ip鍦板潃
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:03",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "2edae9131e77500a56d251b94ab2cdf0bc86f8df9f2453fa46bf4bab2f7be99f",
"EndpointID": "898de81d97d54d2b60aeb6cc77ef1b4f9b481d1b72f542faa496494594024eac",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:03"
}
}
}
}
]
[root@web1 overlay2]# curl 172.17.0.1銆€銆€銆€銆€銆€銆€#璁块棶涓€涓?/span>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test Page for the Nginx HTTP Server on Fedora</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
/*<![CDATA[*/
body {
background-color: #fff;
color: #000;
font-size: 0.9em;
font-family: sans-serif,helvetica;
margin: 0;
padding: 0;
}
:link {
color: #c00;
}
:visited {
color: #c00;
}
a:hover {
color: #f50;
}
h1 {
text-align: center;
margin: 0;
padding: 0.6em 2em 0.4em;
background-color: #294172;
color: #fff;
font-weight: normal;
font-size: 1.75em;
border-bottom: 2px solid #000;
}
h1 strong {
font-weight: bold;
font-size: 1.5em;
}
h2 {
text-align: center;
background-color: #3C6EB4;
font-size: 1.1em;
font-weight: bold;
color: #fff;
margin: 0;
padding: 0.5em;
border-bottom: 2px solid #294172;
}
hr {
display: none;
}
.content {
padding: 1em 5em;
}
.alert {
border: 2px solid #000;
}
img {
border: 2px solid #fff;
padding: 2px;
margin: 2px;
}
a:hover img {
border: 2px solid #294172;
}
.logos {
margin: 1em;
text-align: center;
}
/*]]>*/
</style>
</head>
<body>
<h1>Welcome to <strong>nginx</strong> on Fedora!</h1>
<div class="content">
<p>This page is used to test the proper operation of the
<strong>nginx</strong> HTTP server after it has been
installed. If you can read this page, it means that the
web server installed at this site is working
properly.</p>
<div class="alert">
<h2>Website Administrator</h2>
<div class="content">
<p>This is the default <tt>index.html</tt> page that
is distributed with <strong>nginx</strong> on
Fedora. It is located in
<tt>/usr/share/nginx/html</tt>.</p>
<p>You should now put your content in a location of
your choice and edit the <tt>root</tt> configuration
directive in the <strong>nginx</strong>
configuration file
<tt>/etc/nginx/nginx.conf</tt>.</p>
</div>
</div>
<div class="logos">
<a href="http://nginx.net/"><img
src="nginx-logo.png"
alt="[ Powered by nginx ]"
width="121" height="32" /></a>
<a href="http://fedoraproject.org/"><img
src="poweredby.png"
alt="[ Powered by Fedora ]"
width="88" height="31" /></a>
</div>
</div>
</body>
</html>
[root@web1 overlay2]#
14銆佹煡鐪嬫棩蹇?/span>
-f 鎸傝捣杩欎釜缁堢锛屽姩鎬佹煡鐪嬫棩蹇?/span>
[root@web1 ~]# docker logs -f mynginx
鍙傝€冩枃绔狅細
鎺?/span>鑽?/span>闃?/span>璇?/span>锛?/span>
~
3銆?/span>
4銆?/span>
6
7銆?/span>
- END -
鏈€杩戞暣鐞嗕竴浠借祫鏂?/span>銆婄▼搴忓憳瀛︿範鎵嬪唽銆?/span>锛岃鐩栦簡 Java鎶€鏈€侀潰璇曢绮鹃€夈€佹搷浣滅郴缁熷熀纭€鐭ヨ瘑銆佽绠楁満鍩虹鐭ヨ瘑銆丩inux鏁欑▼銆佽绠楁満缃戠粶绛夌瓑銆?/span> 鑾峰彇鏂瑰紡锛氱偣鈥?nbsp;鍦ㄧ湅锛屽叧娉ㄥ叕浼楀彿 Java澶ф暟鎹慨鐐间箣閬?/strong> 骞跺洖澶?/span> PDF 棰嗗彇锛屾洿澶氬唴瀹归檰缁涓娿€?/span> 闀挎寜璇嗗埆涓嬫柟浜岀淮鐮佸叧娉ㄥ悗鍥炲鍏抽敭瀛? PDF 棰嗗彇
鍏虫敞 java澶ф暟鎹慨鐐间箣閬?/span>
姣忓ぉ瀛︿範java鎶€鏈紝浣犳兂瀛︾殑Java鐭ヨ瘑杩欓噷閮芥湁!
濡傛灉浣犺寰楁枃绔犱笉閿欙紝鏂囨湯鐨勮禐 馃憤 鍙堝洖鏉ュ暒锛? 璁板緱缁欐垜銆岀偣璧炪€嶅拰銆屽湪鐪嬨€嶅摝锝?/strong>
以上是关于(瓒呯骇璇︾粏)Docker 鏋舵瀯鍘熺悊鍙婄畝鍗曚娇鐢╗鏈夐厤濂楄棰慮的主要内容,如果未能解决你的问题,请参考以下文章