锘??xml version="1.0" encoding="utf-8" standalone="yes"?>黄色精品免费,亚洲美洲欧洲综合国产一区,欧美在线观看一区二区三区http://m.shnenglu.com/zhiyewang/category/21191.html鍚戞槦絀轟話鏈涚殑瓚婃繁錛岃秺鍙戠幇鑷繁鐨勬負灝?/description>zh-cnThu, 14 Apr 2016 05:46:27 GMTThu, 14 Apr 2016 05:46:27 GMT60CentOS瀹夎榪愯mongo docker闀滃儚http://m.shnenglu.com/zhiyewang/archive/2016/04/13/213258.htmlzhiye_wangzhiye_wangWed, 13 Apr 2016 03:42:00 GMThttp://m.shnenglu.com/zhiyewang/archive/2016/04/13/213258.htmlhttp://m.shnenglu.com/zhiyewang/comments/213258.htmlhttp://m.shnenglu.com/zhiyewang/archive/2016/04/13/213258.html#Feedback0http://m.shnenglu.com/zhiyewang/comments/commentRss/213258.htmlhttp://m.shnenglu.com/zhiyewang/services/trackbacks/213258.html闃呰鍏ㄦ枃

]]>
Go 璇█鏁欑▼絎旇錛堜笁錛?/title><link>http://m.shnenglu.com/zhiyewang/archive/2016/03/28/213139.html</link><dc:creator>zhiye_wang</dc:creator><author>zhiye_wang</author><pubDate>Mon, 28 Mar 2016 08:54:00 GMT</pubDate><guid>http://m.shnenglu.com/zhiyewang/archive/2016/03/28/213139.html</guid><wfw:comment>http://m.shnenglu.com/zhiyewang/comments/213139.html</wfw:comment><comments>http://m.shnenglu.com/zhiyewang/archive/2016/03/28/213139.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/zhiyewang/comments/commentRss/213139.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/zhiyewang/services/trackbacks/213139.html</trackback:ping><description><![CDATA[<p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong><span style="font-family: 寰蔣闆呴粦, sans-serif;">Go 璇█鏁欑▼絎旇錛?/span><span style="font-family: 寰蔣闆呴粦, sans-serif;">涓?/span><span style="font-family: 寰蔣闆呴粦, sans-serif;">錛?/span></strong><br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>涓 Go璇█鍐崇瓥</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>if 璇彞</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">if璇彞鍖呭惈涓涓竷?yōu)當琛ㄨ緫旨忓悗璺熶竴涓垨澶氫釜璇彞</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">璇硶</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">if璇彞鍦℅o緙栫▼璇█鐨勮娉曟槸錛?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">if(boolean_expression)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">{</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   /* statement(s) will execute if the boolean expression is true */</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">} </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">濡傛灉甯冨皵琛ㄨ揪寮忕殑鍊間負 true錛岄偅涔坕f璇彞閲岄潰浠g爜鍧楀皢琚墽琛屻傚鏋渋f璇彞鐨勭粨鏉?鍙沖ぇ鎷彿鍚?</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">甯冨皵琛ㄨ揪寮忕殑鍊間負false錛岄偅涔堣鍙ヤ箣鍚庣涓琛屼唬鐮佷細琚墽琛屻?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">渚嬪瓙錛?/p><pre tryit"="" style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; line-height: 16px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; cursor: default; background-image: url("http://www.yiibai.com/go/images/try-it.jpg") !important; background-color: #f5f5f5; background-position: 100% 0%; background-repeat: no-repeat !important;">package main import "fmt" func main() { /* local variable definition */ var a int = 10 /* check the boolean condition using if statement */ if( a < 20 ) { /* if condition is true then print the following */ fmt.Printf("a is less than 20\n" ) } fmt.Printf("value of a is : %d\n", a) }</pre><p style="margin-right: 0px; margin-left: 0px; box-sizing: border-box; font-family: 'Open Sans', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 寰蔣闆呴粦, STHeiti, 'WenQuanYi Micro Hei', SimSun, sans-serif, sans-serif; font-size: 16px; color: #535b60; line-height: 22px;">璁╂垜浠紪璇戝拰榪愯涓婇潰鐨勭▼搴忥紝榪欏皢浜х敓浠ヤ笅緇撴灉錛?/p><pre style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; margin-bottom: 0px; line-height: 22px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; background-color: #f1f1f1;">a is less than 20; value of a is : 10</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>if else 璇彞</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">if璇彞鍙互璺熺潃涓涓彲閫夌殑else璇彞錛屽竷?yōu)當琛ㄨ緫旨忔槸鍋囨椂瀹冭鎵ц銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">璇硶</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍦℅o緙栫▼璇█涓殑if ... else璇彞鐨勮娉曟槸錛?/p><pre style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; line-height: 16px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; background-color: #f5f5f5;">if(boolean_expression) { /* statement(s) will execute if the boolean expression is true */ } else { /* statement(s) will execute if the boolean expression is false */ }</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">濡傛灉甯冨皵琛ㄨ揪寮忕殑鍊間負true錛岄偅涔坕f浠g爜鍧楀皢琚墽琛岋紝鍚﹀垯else浠g爜鍧楀皢琚墽琛?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">渚嬪瓙錛?/p><pre tryit"="" style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; line-height: 16px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; cursor: default; background-image: url("http://www.yiibai.com/go/images/try-it.jpg") !important; background-color: #f5f5f5; background-position: 100% 0%; background-repeat: no-repeat !important;">package main import "fmt" func main() { /* local variable definition */ var a int = 100; /* check the boolean condition */ if( a < 20 ) { /* if condition is true then print the following */ fmt.Printf("a is less than 20\n" ); } else { /* if condition is false then print the following */ fmt.Printf("a is not less than 20\n" ); } fmt.Printf("value of a is : %d\n", a); }</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">褰撲笂榪頒唬鐮佽緙栬瘧鍜屾墽琛屾椂錛屽畠浜х敓浜嗕互涓嬬粨鏋滐細</p><pre style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; margin-bottom: 0px; line-height: 22px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; background-color: #f1f1f1;">a is not less than 20; value of a is : 100</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>if...else if...else 璇彞</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">if璇彞鍙互璺熺潃涓涓彲閫夌殑else if ... else璇彞錛岃繖鏄潪甯告湁鐢ㄧ殑浣跨敤鍗曚釜 if...else if 璇彞澹版槑嫻嬭瘯鍚勭鏉′歡銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">褰撲嬌鐢╥f , else if , else璇彞鏈夊嚑鐐硅璁頒綇浣跨敤錛?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">if鍙互鏈夐浂鎴栦竴涓猠lse錛屽畠蹇呴』璺熶粠else if鍚庨潰銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓涓猧f鍙互鏈夐浂鍒頒釜澶歟lse if騫朵笖瀹冧滑蹇呴』鍦╡lse涔嬪墠銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓鏃︿竴涓猠lse if嫻嬭瘯鎴愬姛錛屽叾瀹冧換浣曞墿浣檈lse if灝嗕笉浼氳嫻嬭瘯銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">璇硶</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">if...else if...else鍦℅o緙栫▼璇█涓鍙ョ殑璇硶鏄細</p><pre style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; line-height: 16px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; background-color: #f5f5f5;">if(boolean_expression 1) { /* Executes when the boolean expression 1 is true */ } else if( boolean_expression 2) { /* Executes when the boolean expression 2 is true */ } else if( boolean_expression 3) { /* Executes when the boolean expression 3 is true */ } else { /* executes when the none of the above condition is true */ }</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">渚嬪瓙錛?/p><pre tryit"="" style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; line-height: 16px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; cursor: default; background-image: url("http://www.yiibai.com/go/images/try-it.jpg") !important; background-color: #f5f5f5; background-position: 100% 0%; background-repeat: no-repeat !important;">package main import "fmt" func main() { /* local variable definition */ var a int = 100 /* check the boolean condition */ if( a == 10 ) { /* if condition is true then print the following */ fmt.Printf("Value of a is 10\n" ) } else if( a == 20 ) { /* if else if condition is true */ fmt.Printf("Value of a is 20\n" ) } else if( a == 30 ) { /* if else if condition is true */ fmt.Printf("Value of a is 30\n" ) } else { /* if none of the conditions is true */ fmt.Printf("None of the values is matching\n" ) } fmt.Printf("Exact value of a is: %d\n", a ) }</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">璁╂垜浠紪璇戝拰榪愯涓婇潰鐨勭▼搴忥紝榪欏皢浜х敓浠ヤ笅緇撴灉</p><pre style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; margin-bottom: 0px; line-height: 22px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; background-color: #f1f1f1;">None of the values is matching Exact value of a is: 100</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>switch 璇彞</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">switch璇彞鍙互璁╀竴涓彉閲忓鍙嶅鍊肩殑鍒楄〃騫崇瓑榪涜嫻嬭瘯銆傛瘡涓艱縐頒負涓涓殑鎯呭喌(case)錛?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍙橀噺琚帴閫氭鏌ユ瘡涓紑鍏崇洅(switch case)銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍦℅o緙栫▼錛宻witch鏈変袱縐嶇被鍨嬨?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"> <span style="font-family: 寰蔣闆呴粦, sans-serif;">琛ㄨ揪寮廠witch - 鍦ㄨ〃杈懼紡switch錛宑ase鍖呭惈鐩告瘮杈冿紝switch琛ㄨ揪寮忕殑鍊箋?/span></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"> <span style="font-family: 寰蔣闆呴粦, sans-serif;">綾誨瀷Switch - 鍦ㄨ繖綾誨瀷switch錛屾鏃跺惈鏈夎繘琛屾瘮杈冪壒孌婃敞鏄庡紑鍏寵〃杈懼紡鐨勭被鍨嬨?/span></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong> <span style="font-family: 寰蔣闆呴粦, sans-serif;">琛ㄨ揪寮廠witch</span></strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍦℅o緙栫▼璇█涓〃杈緎witch璇彞鐨勮娉曞涓嬶細</p><pre style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; line-height: 16px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; background-color: #f5f5f5;">switch(boolean-expression or integral type){ case boolean-expression or integral type : statement(s); case boolean-expression or integral type : statement(s); /* you can have any number of case statements */ default : /* Optional */ statement(s); }</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">浠ヤ笅瑙勫垯閫傜敤浜巗witch璇彞錛?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍦╯witch璇彞涓嬌鐢ㄧ殑琛ㄨ揪寮忓繀欏誨叿鏈夋暣浣撴垨甯冨皵琛ㄨ揪寮忥紝鎴栬呮槸涓涓被鍨嬶紝鍏朵腑鎵榪扮被鍏鋒湁</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓涓崟涓鐨勮漿鎹㈠嚱鏁幫紝浠ヤ竴涓暣浣撴垨甯冨皵鍊箋傚鏋滆〃杈句笉閫氳繃錛岄粯璁ゅ兼槸true銆?span style="font-family: 寰蔣闆呴粦, sans-serif;">鍙互鏈変換鎰忔暟</span></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><span style="font-family: 寰蔣闆呴粦, sans-serif;">閲忕殑case璇彞鍦╯witch鍐呫傛瘡涓猚ase鍚庤窡鍊艱繘琛屾瘮杈冿紝浠ュ強涓涓啋鍙楓?/span><span style="font-family: 寰蔣闆呴粦, sans-serif;">constant-expression </span></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><span style="font-family: 寰蔣闆呴粦, sans-serif;">鐨勬儏鍐碉紝蹇呴』鏄浉鍚岀殑鏁版嵁綾誨瀷錛屽湪switch鐨勫彉閲忥紝瀹冨繀欏繪槸涓涓父閲?/span><span style="font-family: 寰蔣闆呴粦, sans-serif;">鎴栨枃瀛椼?/span></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">褰撳彉閲忚鎺ラ氱瓑浜巆ase鐨勫鹼紝浠ヤ笅case涓皢鎵ц璇彞銆傚湪case璇彞涓璪reak涓嶆槸蹇呴渶銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">switch璇彞鍙互鏈変竴涓彲閫夐粯璁ゆ儏鍐典笅錛屽畠蹇呴』鍑虹幇鍦ㄥ紑鍏崇粨鏉熴傜己鐪佹儏鍐典笅錛屽彲鐢ㄤ簬鎵ц浠?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍔℃椂娌℃湁鐨刢ase涓簍rue銆傚垯case鍦ㄩ粯璁ゆ儏鍐典笅涔熶笉鏄繀欏葷殑銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">渚嬪瓙</p><pre tryit"="" style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; line-height: 16px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; cursor: default; background-image: url("http://www.yiibai.com/go/images/try-it.jpg") !important; background-color: #f5f5f5; background-position: 100% 0%; background-repeat: no-repeat !important;">package main import "fmt" func main() { /* local variable definition */ var grade string = "B" var marks int = 90 switch marks { case 90: grade = "A" case 80: grade = "B" case 50,60,70 : grade = "C" default: grade = "D" } switch { case grade == "A" : fmt.Printf("Excellent!\n" ) case grade == "B", grade == "C" : fmt.Printf("Well done\n" ) case grade == "D" : fmt.Printf("You passed\n" ) case grade == "F": fmt.Printf("Better try again\n" ) default: fmt.Printf("Invalid grade\n" ); } fmt.Printf("Your grade is %s\n", grade ); }</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">褰撲笂榪頒唬鐮佽緙栬瘧鍜屾墽琛屾椂錛屽畠浜х敓浜嗕互涓嬬粨鏋滐細</p><pre style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; margin-bottom: 0px; line-height: 22px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; background-color: #f1f1f1;">Well done Excellent! Your grade is A</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>綾誨瀷Switch</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍦℅o緙栫▼璇█鐨勪竴涓被鍨媠witch璇彞鐨勮娉曞涓嬶細</p><pre style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; line-height: 16px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; background-color: #f5f5f5;">switch x.(type){ case type: statement(s); case type: statement(s); /* you can have any number of case statements */ default: /* Optional */ statement(s); }</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">浠ヤ笅瑙勫垯閫傜敤浜巗witch璇彞錛?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍦╯witch璇彞涓嬌鐢ㄥ繀欏繪湁鎺ュ彛鐨勫彉閲忚〃杈懼紡{}杈撳叆銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍦╯witch鍐呭彲浠ユ湁浠繪剰鏁伴噺case璇彞銆傛瘡涓縐峜ase鍚庤窡鐨勫艱繘琛屾瘮杈冿紝浠ュ強涓涓啋鍙楓?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">case 綾誨瀷蹇呴』鏄浉鍚岀殑鏁版嵁綾誨瀷錛屽湪switch鐨勫彉閲忥紝瀹冨繀欏繪槸涓涓湁鏁堢殑鏁版嵁綾誨瀷銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">褰撳彉閲忚鎺ラ氱瓑浜庢煇涓case涓殑鍊鹼紝浠ヤ笅case璇彞灝嗘墽琛屻傚湪case璇彞鍧楃殑break涓嶆槸蹇呴渶鐨勩?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">switch璇彞鍙互鏈変竴涓彲閫夐粯璁ase錛屽畠蹇呴』鍑虹幇鍦╯witch鐨勭粨鏉熴傜己鐪佹儏鍐典笅錛屽彲鐢ㄤ簬鎵ц</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">浠誨姟鏃舵病鏈夊尮閰峜ase鏃躲俤efault涓嶆槸蹇呴渶鐨勩?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">渚嬪瓙</p><pre tryit"="" style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; line-height: 16px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; cursor: default; background-image: url("http://www.yiibai.com/go/images/try-it.jpg") !important; background-color: #f5f5f5; background-position: 100% 0%; background-repeat: no-repeat !important;">package main import "fmt" func main() { var x interface{} switch i := x.(type) { case nil: fmt.Printf("type of x :%T",i) case int: fmt.Printf("x is int") case float64: fmt.Printf("x is float64") case func(int) float64: fmt.Printf("x is func(int)") case bool, string: fmt.Printf("x is bool or string") default: fmt.Printf("don't know the type") } }</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">璁╂垜浠紪璇戝拰榪愯涓婇潰鐨勭▼搴忥紝榪欏皢浜х敓浠ヤ笅緇撴灉錛?/p><pre style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; margin-bottom: 0px; line-height: 22px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; background-color: #f1f1f1;">type of x :<nil></pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong> select璇彞</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">select璇彞鐨勮娉曞涓嬶細</p><pre style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; line-height: 16px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; background-color: #f5f5f5;">select { case communication clause : statement(s); case communication clause : statement(s); /* you can have any number of case statements */ default : /* Optional */ statement(s); }</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">浠ヤ笅瑙勫垯閫傜敤浜巗elect璇彞錛?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍙互鏈変換鎰忔暟閲忕殑鑼冨洿鍐呴夋嫨涓涓猚ase璇彞銆傛瘡涓縐嶆儏鍐典笅鍚庤窡鐨勫艱繘琛屾瘮杈冿紝浠ュ強涓涓啋鍙楓?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">瀵逛簬case鐨勭被鍨嬪繀欏繪槸涓涓氫俊閫氶亾鎿嶄綔銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">褰撻氶亾榪愯涓嬮潰鍙戠敓鐨勮鍙ヨ繖縐嶆儏鍐靛皢鎵ц銆傚湪case璇彞涓璪reak涓嶆槸蹇呴渶鐨勩?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">select璇彞鍙互鏈変竴涓彲閫夐粯璁ase錛屽畠蹇呴』鍑虹幇鍦╯elect鐨勭粨鏉熷墠銆傜己鐪佹儏鍐典笅錛屽彲鐢ㄤ簬鎵ц</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">浠誨姟鏃舵病鏈夌殑鎯呭喌涓嬫槸鐪熷疄鐨勩傚湪榛樿鎯呭喌涓媌reak涓嶆槸蹇呴渶鐨勩?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">渚嬪錛?/p><pre tryit"="" style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; line-height: 16px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; cursor: default; background-image: url("http://www.yiibai.com/go/images/try-it.jpg") !important; background-color: #f5f5f5; background-position: 100% 0%; background-repeat: no-repeat !important;">package main import "fmt" func main() { var c1, c2, c3 chan int var i1, i2 int select { case i1 = <-c1: fmt.Printf("received ", i1, " from c1\n") case c2 <- i2: fmt.Printf("sent ", i2, " to c2\n") case i3, ok := (<-c3): // same as: i3, ok := <-c3 if ok { fmt.Printf("received ", i3, " from c3\n") } else { fmt.Printf("c3 is closed\n") } default: fmt.Printf("no communication\n") } } </pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">璁╂垜浠紪璇戝拰榪愯涓婇潰鐨勭▼搴忥紝榪欏皢浜х敓浠ヤ笅緇撴灉錛?/p><pre style="box-sizing: border-box; font-family: 'Courier New', Courier, monospace; overflow: auto; padding: 0.5em; margin-bottom: 0px; line-height: 22px; word-break: break-all; word-wrap: break-word; color: #313131; border-width: 1px 1px 1px 3px; border-style: solid; border-color: #cccccc; border-radius: 0px; white-space: pre-wrap; width: 604px; background-color: #f1f1f1;">no communication</pre><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">​</p><img src ="http://m.shnenglu.com/zhiyewang/aggbug/213139.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/zhiyewang/" target="_blank">zhiye_wang</a> 2016-03-28 16:54 <a href="http://m.shnenglu.com/zhiyewang/archive/2016/03/28/213139.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Go 璇█鏁欑▼絎旇錛堜簩http://m.shnenglu.com/zhiyewang/archive/2016/03/28/213136.htmlzhiye_wangzhiye_wangMon, 28 Mar 2016 08:17:00 GMThttp://m.shnenglu.com/zhiyewang/archive/2016/03/28/213136.htmlhttp://m.shnenglu.com/zhiyewang/comments/213136.htmlhttp://m.shnenglu.com/zhiyewang/archive/2016/03/28/213136.html#Feedback0http://m.shnenglu.com/zhiyewang/comments/commentRss/213136.htmlhttp://m.shnenglu.com/zhiyewang/services/trackbacks/213136.htmlGo 璇█鏁欑▼絎旇錛堜簩錛?/strong>

涓 Go 璇█甯擱噺

甯擱噺鏄寚璇ョ▼搴忓彲鑳芥棤娉曞湪鍏舵墽琛屾湡闂存敼鍙樼殑鍥哄畾鍊箋傝繖浜涘浐瀹氬間篃琚О涓烘枃瀛椼?/p>

甯擱噺鍙互鏄換浣曞儚涓涓暣鍨嬪父閲忥紝涓涓誕鐐瑰父閲忥紝瀛楃甯擱噺鎴栧瓧絎︿覆鏂囧瓧鐨勫熀鏈暟鎹被鍨嬨傝繕

鏈夋灇涓懼父閲忋?span style="font-family: 寰蔣闆呴粦, sans-serif;">甯擱噺鏄竴鏍鳳紝鍙槸瀹冧滑鐨勫間笉鑳借嚜宸卞畾涔夊悗榪涜淇敼甯歌鍙橀噺澶勭悊銆?/span>

鏁村艦甯擱噺

涓涓暣鏁版枃瀛椾篃鍙互鏈変竴涓悗緙涓篣鍜孡鐨勭粍鍚堬紝鍒嗗埆涓烘棤絎﹀彿鍜岄暱鏁村瀷銆傚悗緙鍙互鏄ぇ鍐欐垨灝?/p>

鍐欙紝騫朵笖鍙互浠ヤ換鎰忛『搴忋?span style="font-family: 寰蔣闆呴粦, sans-serif;">鍙互鏄崄榪涘埗錛屽叓榪涘埗錛屾垨鍗佸叚榪涘埗甯告暟銆傚墠緙鎸囧畾鍩烘垨鍩烘暟錛?x

鎴?0X 鐨勫崄鍏繘鍒訛紝0 琛ㄧず鍏繘鍒訛紝騫舵病鏈夊崄榪涘埗銆?/span>

鏁存暟甯擱噺鐨勪竴浜涗緥瀛愶細

212         /* Legal */

215u        /* Legal */

0xFeeL      /* Legal */

078         /* Illegal: 8 is not an octal digit */

032UU       /* Illegal: cannot repeat a suffix */

涓嶅悓綾誨瀷鐨勬暣鍨嬪父閲忕殑渚嬪瓙錛?/p>

85         /* decimal */

0213       /* octal */

0x4b       /* hexadecimal */

30         /* int */

30u        /* unsigned int */

30l        /* long */

30ul       /* unsigned long */

嫻偣鏂囨湰(甯擱噺)

嫻偣瀛楅潰鍏鋒湁涓涓暣鏁伴儴鍒嗭紝涓涓皬鏁扮偣錛屼竴涓皬鏁伴儴鍒嗭紝鍜屼竴涓寚鏁伴儴鍒嗐備綘鍙互琛ㄧず鍗佽繘

鍒跺艦寮忔垨鎸囨暟褰㈠紡嫻偣鏂囧瓧銆?span style="font-family: 寰蔣闆呴粦, sans-serif;">鍚屾椂閲囩敤鍗佽繘鍒跺艦寮忚〃紺猴紝鍒欏繀欏誨寘鎷皬鏁扮偣錛屾寚鏁幫紝鎴栦袱鑰呭茍

鐢ㄨ屾寚鏁板艦寮忚〃紺猴紝鍒欏繀欏誨寘鎷暣鏁伴儴鍒嗭紝灝忔暟閮ㄥ垎錛屾垨鑰呬袱鑰呭吋鑰屾湁涔嬨傛湁絎﹀彿鐨勬寚鏁幫紝閫?/span>

榪噀鎴朎琛ㄧず銆?/span>

涓嬮潰鏄誕鐐歸潰鍊肩殑涓浜涗緥瀛愶細

3.14159       /* Legal */

314159E-5L    /* Legal */

510E          /* Illegal: incomplete exponent */

210f          /* Illegal: no decimal or exponent */

.e55          /* Illegal: missing integer or fraction */

瀛楃涓叉枃瀛?/strong>

瀛楃涓叉枃瀛楁垨甯擱噺鐢ㄥ弻寮曞彿“”銆備竴涓瓧絎︿覆鍖呭惈綾諱技浜庡瓧絎︽枃瀛楀瓧絎︼細鏅氬瓧絎︼紝杞箟搴忓垪

鍜岄氱敤瀛楃銆?span style="font-family: 寰蔣闆呴粦, sans-serif;">鍙互浣跨敤瀛楃涓插拰鍒嗛殧浣跨敤絀烘牸鎵撶牬涓涓暱琛屾垚澶氳銆?/span>

"hello, dear"

"hello, 

dear"

"hello, " "d" "ear"

const 鍏抽敭瀛?/strong>

package main

import "fmt"

func main() {

   const LENGTH int = 10

   const WIDTH int = 5   

   var area int

   area = LENGTH * WIDTH

   fmt.Printf("value of area : %d", area)   

}

涔犳儻澶у啓瀹氫箟甯擱噺鏄竴涓壇濂界殑緙栫▼涔犳儻銆?/span>

浜?Go 璇█榪愮畻絎?/strong>

Go璇█鏈変赴瀵岀殑鍐呯疆榪愮畻絎﹀拰榪愮畻絎︼細

綆楁湳榪愮畻絎?/p>

鍏崇郴榪愮畻絎?/p>

閫昏緫榪愮畻絎?/p>

浣嶈繍綆楃

璧嬪艱繍綆楃

鍏跺畠榪愮畻絎?/p>


綆楁湳榪愮畻絎?/strong>

榪愮畻絎?/th>鎻忚堪紺轟緥
+涓や釜鎿嶄綔鏁扮浉鍔?/td>A + B = 30
-絎竴涓搷浣滄暟鍑忕浜屾搷浣滄暟A - B = -10
*涓や釜鎿嶄綔鏁扮浉涔?/td>A * B = 200
/閫氳繃鍘誨垎瀛愰櫎浠ュ垎姣?/td>B / A = 2
%妯¤繍綆楀拰鏁存暟闄ゆ硶鍚庣殑浣欐暟B % A = 0
++榪愮畻絎﹂掑鏁存暟鍊煎鍔犱竴A++ = 11
--榪愮畻絎﹂掑噺鏁存暟鍊煎噺涓A-- = 9

鍏崇郴榪愮畻絎?/strong>

榪愮畻絎?/th>鎻忚堪紺轟緥
==媯鏌ヤ袱涓搷浣滄暟鐨勫兼槸鍚︾浉絳夛紝濡傛灉鏄殑璇濋偅涔堟潯浠朵負鐪熴?/td>(A == B) 涓嶄負 true.
!=媯鏌ヤ袱涓搷浣滄暟鐨勫兼槸鍚︾浉絳夛紝濡傛灉鍊間笉鐩哥瓑錛屽垯鏉′歡鍙樹負鐪熴?/td>(A != B) 涓簍rue.
>媯鏌ュ乏杈圭殑鎿嶄綔鏁扮殑鍊兼槸鍚﹀ぇ浜庡彸鎿嶄綔鏁扮殑鍊鹼紝濡傛灉鏄殑璇濋偅涔堟潯浠朵負鐪熴?/td>(A > B) 涓嶄負 true.
<媯鏌ュ乏杈圭殑鎿嶄綔鏁扮殑鍊兼槸鍚﹀皬浜庡彸鎿嶄綔鏁扮殑鍊鹼紝濡傛灉鏄殑璇濋偅涔堟潯浠朵負鐪熴?/td>(A < B) 涓?nbsp;true.
>=媯鏌ュ乏杈圭殑鎿嶄綔鏁扮殑鍊兼槸鍚﹀ぇ浜庢垨絳変簬鍙蟲搷浣滄暟鐨勫鹼紝濡傛灉鏄殑璇濋偅涔堟潯浠朵負鐪熴?/td>(A >= B) 涓嶄負 true.
<=媯鏌ュ乏杈圭殑鎿嶄綔鏁扮殑鍊兼槸鍚﹀皬浜庢垨絳変簬鍙蟲搷浣滄暟鐨勫鹼紝濡傛灉鏄殑璇濋偅涔堟潯浠朵負鐪熴?/td>(A <= B) 涓?nbsp;true

閫昏緫榪愮畻絎?/span>

&&鎵璋撻昏緫涓庤繍綆楃銆傚鏋滀袱涓搷浣滄暟閮介潪闆訛紝鍒欐潯浠跺彉涓虹湡銆?/td>(A && B) 涓?false.
||鎵璋撶殑閫昏緫鎴栨搷浣溿傚鏋滀換浣曚袱涓搷浣滄暟鏄潪闆訛紝鍒欐潯浠跺彉涓虹湡銆?/td>(A || B) 涓?nbsp;true.
!鎵璋撻昏緫闈炶繍綆楃銆備嬌鐢ㄥ弽杞搷浣滄暟鐨勯昏緫鐘舵併傚鏋滄潯浠朵負鐪燂紝閭d箞閫昏緫闈炴搷鍚庣粨鏋滀負鍋囥?/td>!(A && B) 涓?nbsp;true.

浣嶈繍綆楃

pqp & qp | qp ^ q
00000
01011
11110
10011

鍋囪錛屽鏋淎 =60;涓攂 =13;鐜板湪浠ヤ簩榪涘埗鏍煎紡瀹冧滑濡備笅錛?/p>

A = 0011 1100

B = 0000 1101

-----------------

A&B = 0000 1100

A|B = 0011 1101

A^B = 0011 0001

~A  = 1100 0011

C璇█鏀寔浣嶈繍綆楃鍒楀湪濡備笅琛ㄣ傚亣璁懼彉閲廇=60鍜屽彉閲廈=13錛屽垯

鍏跺畠榪愮畻絎?/strong>

榪樻湁鍏朵粬涓浜涢噸瑕佺殑榪愮畻絎︼紝鍖呮嫭sizeof鍜?:鍦℅o璇█涓篃鏀寔銆?/p>

Go璇█榪愮畻絎︿紭鍏堢駭

鍒嗙被 榪愮畻絎?nbsp;鍏寵仈 
鍚庣紑() [] -> . ++ - -  浠庡乏鍒板彸
涓鍏?/td>+ - ! ~ ++ - - (type)* & sizeof 浠庡彸鍒板乏
涔樻硶* / % 浠庡乏鍒板彸
鐩稿姞  + - 浠庡乏鍒板彸 
縐誨姩<< >> 浠庡乏鍒板彸
鍏崇郴< <= > >= 浠庡乏鍒板彸
鐩哥瓑== != 浠庡乏鍒板彸
鎸変綅涓?/td>浠庡乏鍒板彸
鎸変綅寮傛垨浠庡乏鍒板彸
鎸変綅鎴?nbsp;浠庡乏鍒板彸
閫昏緫涓?nbsp;&& 浠庡乏鍒板彸
閫昏緫鎴?nbsp;|| 浠庡乏鍒板彸
鏉′歡 ?: 浠庡乏鍒板彸
璧嬪?/td>= += -= *= /= %=>>= <<= &= ^= |= 浠庡彸鍒板乏
閫楀彿 浠庡乏鍒板彸


]]>
Go 璇█鏁欑▼絎旇錛堜竴錛?/title><link>http://m.shnenglu.com/zhiyewang/archive/2016/03/28/213135.html</link><dc:creator>zhiye_wang</dc:creator><author>zhiye_wang</author><pubDate>Mon, 28 Mar 2016 07:33:00 GMT</pubDate><guid>http://m.shnenglu.com/zhiyewang/archive/2016/03/28/213135.html</guid><wfw:comment>http://m.shnenglu.com/zhiyewang/comments/213135.html</wfw:comment><comments>http://m.shnenglu.com/zhiyewang/archive/2016/03/28/213135.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/zhiyewang/comments/commentRss/213135.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/zhiyewang/services/trackbacks/213135.html</trackback:ping><description><![CDATA[<p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>Go 璇█鏁欑▼絎旇錛堜竴錛?/strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>涓 Go 璇█鐜璁劇疆 </strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>鏈湴鐜璁劇疆</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍦ㄨ繖閲屾垜浠粙緇嶈緗瓽o緙栫▼璇█鐜錛岄渶瑕佸湪浣犵殑璁$畻鏈轟笂鐨勫噯澶囦互涓嬩袱涓蔣浠訛紝(A)鏂囨湰緙?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">杈戝櫒鍜?B)Go緙栬瘧鍣ㄣ?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>鏂囨湰緙栬緫鍣?/strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鎴戠殑鐜鏄痷buntu錛岀洿鎺ョ敤 vim</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>Go緙栬瘧鍣?/strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">ubuntu涓嬮潰鐩存帴瀹夎</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"># apt-get install golang</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">渚嬪瓙錛?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"># vim hello.go</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  1 package main</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  2 </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  3 import fmt "fmt"</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  4 </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  5 func main() {</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  6     fmt.Printf("Hello, world; or Καλημέρα κόσμε; or 銇撱倱銇仭銇?nbsp;涓栫晫 ");</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  7 }                                                                        </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">go璇█涓鏋滄湁if絳夊悗闈㈤渶瑕佽窡澶ф嫭鍙風殑璇彞錛屽己鍒朵嬌鐢ㄥぇ鎵╁彿璺焛f鍐欏湪涓琛?span style="font-family: 寰蔣闆呴粦, sans-serif;">銆?/span></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><span style="font-family: 寰蔣闆呴粦, sans-serif;"><br /></span></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><span style="font-family: 寰蔣闆呴粦, sans-serif;">緙栬瘧榪愯錛?/span></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"># go run hello.go </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">Hello, world; or Καλημέρα κόσμε; or 銇撱倱銇仭銇?nbsp;涓栫晫</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong><span style="font-family: 寰蔣闆呴粦, sans-serif;">浜?Go 璇█紼嬪簭緇撴瀯 </span></strong><span style="font-family: 寰蔣闆呴粦, sans-serif;"><br /></span></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍦ㄦ垜浠涔燝o緙栫▼璇█鐨勫熀鏈瀯寤烘ā鍧楋紝鐪嬬湅涓涓渶浣庨檺搴︾殑Go紼嬪簭緇撴瀯錛岃繖鏍鋒垜浠?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">灝卞彲浠ユ妸瀹冧綔涓哄嵆灝嗗埌鏉ョ殑绔犺妭鐨勫弬鑰冦?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>Go 紼嬪簭鍖呭惈浠ヤ笅閮ㄥ垎</strong>錛?br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍖呭0鏄?br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">瀵煎叆鍖?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍑芥暟</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍙橀噺</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">璇彞鍜岃〃杈懼紡</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">娉ㄩ噴</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">渚嬪錛?br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"> 1 package main</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  2 </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  3 import fmt "fmt"</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  4 </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  5 func main() {</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  6     fmt.Printf("Hello, world; or Καλημέρα κόσμε; or 銇撱倱銇仭銇?nbsp;涓栫晫 ");</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">  7 }  </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">絎竴琛屽畾涔変簡榪欎釜紼嬪簭鍖呯殑鍚嶇О銆傝繖鏄竴涓繀欏誨0鏄庝負Go紼嬪簭榪愯鍦ㄤ粈涔堝寘銆俶ain鍖呮槸璧峰</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鐐規(guī)潵榪愯紼嬪簭銆傛瘡涓寘閮芥湁涓涓笌涔嬪叧鑱旂殑璺緞鍜屽悕縐般?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓嬩竴琛宨mport "fmt" 鏄憡璇夌紪璇戝櫒鍘誨寘鍚枃浠跺湪鍖協(xié)mt鐨勯澶勭悊鍛戒護銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓嬩竴琛?nbsp;func main()涓昏鍔熻兘鏄負紼嬪簭鎵ц鐨勫紑濮嬨?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">濡傛灉鏈夋敞閲婏紝/*...*/浼氳緙栬瘧鍣ㄨ蹇界暐錛屽畠宸茶鍔犲叆鍒扮▼搴忔坊鍔犳敞閲娿傚洜姝わ紝榪欐牱鐨勮縐頒負紼?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">搴忎腑鐨勬敞閲娿傛敞閲婁篃浣跨敤//綾諱技浜嶫ava鎴朇++娉ㄩ噴銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓嬩竴琛?nbsp;fmt.Println錛?..錛夋槸鎻愪緵鍙︿竴縐嶅姛鑳斤紝浣挎秷鎭?#8220;Hello, World!”瑕佹樉紺哄湪灞忓箷涓娿傝繖</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">閲宖mt鍖呭凡瀵煎嚭銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>涓?Go 璇█鐨勫熀鏈娉?/strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>鏍囪瘑絎?/strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">Go璇█涓嶅厑璁告爣璇嗙涓殑鏍囩偣瀛楃錛屽@錛?鍜?銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">Go鏄竴縐嶅尯鍒嗗ぇ灝忓啓鐨勭紪紼嬭璦</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">Manpower 鍜?nbsp;manpower 鍦℅o涓槸涓や釜涓嶅悓鐨勬爣璇嗙</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鏍囪瘑絎﹀紑濮嬩互瀛楁瘝A鍒癦鎴朼鍒皕鎴栦笅鍒掔嚎_鍚庤窡闆朵釜鎴栧涓瓧姣嶏紝涓嬪垝綰垮拰鏁板瓧錛?銆?錛?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>鍏抽敭璇?/strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓嬮潰鐨勫垪琛ㄦ樉紺轟簡Go鐨勪繚鐣欏瓧銆傝繖浜涗繚鐣欑殑瀛楀彲浠ヤ笉琚敤浣滃父閲忔垨鍙橀噺錛屾垨浠諱綍鍏朵粬鐨勬爣璇嗙</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍚嶇О銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">break  default  func  interface  select</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">case  defer  go  map  struct</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">chan  else  goto  package  switch</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">const  fallthrough  if  range  type</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">continue  for  import  return  var</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>鍦?Go 涓┖鐧芥牸</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">浠呭寘鍚┖鏍鹼紝鍙兘涓庢敞閲婅錛岃縐頒負涓涓┖琛岋紝Go緙栬瘧鍣ㄥ畬鍏ㄥ拷鐣ュ畠銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">var age int;</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">蹇呴』鏈夎嚦灝戜竴涓┖鐧藉瓧絎︼紙閫氬父鏄竴涓┖鏍鹼級int鍜宎ge涔嬮棿鐨勭紪璇戝櫒錛屼互渚胯兘澶熷尯鍒嗗畠浠?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">fruit = apples + oranges;   // get the total fruit</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">fruit鍜?涔嬮棿鎴?鍜宎pples錛岃櫧鐒舵槸鑷敱鐨勶紝濡傛灉鎯充究浜庨槄璇葷殑鐩殑錛屾渶濂藉寘鎷竴浜涚┖鏍?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>鍥?Go 璇█鏁版嵁綾誨瀷</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍦℅o緙栫▼璇█錛屾暟鎹被鍨嬫寚鐢ㄤ簬澹版槑鍙橀噺鎴栦笉鍚岀被鍨嬬殑鍔熻兘鐨勫箍娉涚殑緋葷粺銆傚彉閲忕殑綾誨瀷鍐沖畾浜?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鏈夊灝戠┖闂村崰鐢ㄧ殑瀛樺偍鍜屽瓨鍌ㄦ柟寮忕殑浣嶆ā寮忓皢琚В閲娿?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">Go鐨勬暟鎹被鍨嬪彲鍒嗙被濡備笅錛?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">Boolean Types</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">瀹冧滑鏄竷?yōu)當绫诲瀷锛屽畠鐢变袱涓瀹氫箟鐨勫笖R噺錛?a) true (b) false</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">Numeric Types</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">瀹冧滑鏄畻鏈被鍨嬶紝琛ㄧず鏁存暟綾誨瀷鎴朾銆傚湪鏁翠釜紼嬪簭嫻偣鍊?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">string types:</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓涓瓧絎︿覆綾誨瀷浠h〃緇勫瓧絎︿覆鍊箋傚畠鐨勫兼槸涓涓瓧鑺傚簭鍒椼傚瓧絎︿覆鏄竴嬈″垱閫犱簡紼沖畾鐨勭被鍨嬶紝</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">榪欐槸涓嶅彲鑳芥敼鍙樹竴涓瓧絎︿覆鐨勫唴瀹廣傞澹版槑鐨勫瓧絎︿覆綾誨瀷涓哄瓧絎︿覆銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">Derived types:</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">瀹冧滑鍖呮嫭錛?a)鎸囬拡綾誨瀷錛?b)鏁扮粍綾誨瀷錛?c)緇撴瀯綾誨瀷錛?d)鑱旂洘綾誨瀷鍙?e)鍑芥暟綾誨瀷(f)鍒囩墖綾?g)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍑芥暟綾誨瀷(h)鎺ュ彛綾誨瀷(i)鍦板浘綾誨瀷(j)綆¢亾綾誨瀷銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鏁扮粍綾誨瀷鍜岀粨鏋勭被鍨嬭緇熺О涓鴻仛鍚堢被鍨嬨傚嚱鏁扮殑綾誨瀷鎸囧畾鐨勪竴緇勫叿鏈夌浉鍚岀殑鍙傛暟鍜岀粨鏋滅被鍨嬫墍</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鏈夊嚱鏁般?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>鏁存暟</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">1 uint8</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">8浣嶆棤絎﹀彿鏁存暟 (0 - 255)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">2 uint16</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">16浣嶆棤絎﹀彿鏁存暟 (0 - 65535)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">3 uint32</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">32浣嶆棤絎﹀彿鏁存暟 (0 - 4294967295)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">4  uint64</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">64浣嶆棤絎﹀彿鏁存暟 (0 - 18446744073709551615)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">5  int8</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鏈夌鍙?浣嶆暣鏁?nbsp;(-128 - 127)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">6  int16</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鏈夌鍙?6浣嶆暣鏁?nbsp;(-32768 - 32767)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">7  int32</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鏈夌鍙風殑32浣嶆暣鏁?nbsp;(-2147483648 - 2147483647)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">8  int64</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鏈夌鍙風殑64浣嶆暣鏁?nbsp;(-9223372036854775808 - 9223372036854775807)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>嫻偣綾誨瀷</strong><br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">1  float32</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">IEEE-754 32-bit 嫻偣鏁?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">2  float64</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">IEEE-754 64-bit 嫻偣鏁?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">3  complex64</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">澶嶆暟涓巉loat32瀹為儴鍜岃櫄閮?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">4  complex128</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">澶嶆暟涓巉loat64瀹為儴鍜岃櫄閮?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>鍏朵粬鏁板肩被鍨?/strong><br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">1  byte</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鐩稿悓浜?nbsp;uint8</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">2  rune</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鐩稿悓浜?nbsp;int32</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">3  uint</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">32 鎴?nbsp;64 浣?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">4  int</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鐩稿悓浜?nbsp;uint 鐨勫ぇ灝?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">5  uintptr</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓涓棤絎﹀彿鏁存暟鏉ュ瓨鍌ㄦ寚閽堝肩殑瑙i噴鐨勬瘮鐗逛綅</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>浜?Go 璇█鍙橀噺</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍙橀噺鏄粈涔堬紝鍙笉鏄粰瀹氬埌瀛樺偍鍖哄煙錛屾垜浠殑紼嬪簭鍙互鎿嶇旱鐨勫悕縐般傚湪Go涓瘡涓彉閲忓叿鏈夌壒瀹?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鐨勭被鍨嬶紝瀹冪‘瀹氱殑澶у皬鍜屽彲鍙樼殑瀛樺偍鍣ㄧ殑甯冨眬;鑳界‘瀹氬瓨鍌ㄥ櫒鍐呭瓨鍌ㄧ殑鍊肩殑鑼冨洿;鍜岀粍鎿嶄綔鍙互鏂?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍔犲埌鍙橀噺銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓涓彉閲忓悕鍙互鐢卞瓧姣嶏紝鏁板瓧鍜屼笅鍒掔嚎銆傚畠蹇呴』浠ュ瓧姣嶆垨涓嬪垝綰褲傚ぇ鍐欏拰灝忓啓瀛楁瘝鏄笉鍚岀殑錛屽洜</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓篏o鏄尯鍒嗗ぇ灝忓啓鐨勩傚熀浜庤鍩烘湰綾誨瀷鍦ㄥ墠闈㈢殑绔犺妭涓鏄庣殑閭f牱錛屽皢鏈変互涓嬪熀鏈彉閲忕被鍨嬶細</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">byte  閫氬父鍗曚釜瀛楄妭(涓涓瓧鑺?錛岃繖鏄竴涓瓧鑺傜殑綾誨瀷</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">int  鏁存暟鏈鑷劧鐨勫昂瀵哥殑鏈哄櫒</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">float32  鍗曠簿搴︽誕鐐瑰?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">Go緙栫▼璇█涔熷彲浠ュ畾涔夊悇縐嶅叾浠栫被鍨嬬殑鍙橀噺錛屾垜浠皢鍦ㄤ互鍚庣殑绔犺妭鍒楀嚭錛屽錛氭灇涓撅紝鎸囬拡錛屾暟</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">緇勶紝緇撴瀯錛岃仈鍚堬紝絳夌瓑銆?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>Go涓彉閲忓畾涔?/strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">var variable_list optional_data_type;</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">optional_data_type鍙互鍖呮嫭瀛楄妭錛屾暣鍨嬶紝float32錛宑omplex64錛屽竷?yōu)當鎴栦恢M綍鐢ㄦ埛瀹氫箟鐨勫璞?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">絳夋湁鏁圙o鐨勬暟鎹被鍨嬶紝variable_list鍙互鐢辯敤閫楀彿鍒嗛殧鐨勪竴涓垨澶氫釜鏍囪瘑絎﹀悕縐般備竴浜涙湁鏁堢殑澹?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鏄庡涓嬫墍紺猴細</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">var    i, j, k int;</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">var   c, ch byte;</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">var  f, salary float32;</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">d = 42;</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">var i, j, k; 鏃㈠0鏄庡茍瀹氫箟浜嗗彉閲廼錛宩鍜宬;榪欐寚紺虹紪璇戝櫒鍒涘緩涓涓悕涓篿錛宩鍜宬鐨?nbsp;int綾誨瀷鍙橀噺銆傚彉閲?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鍙互鍐嶅0鏄庢椂鍊欏垵濮嬪寲銆傚彉閲忕殑綾誨瀷鏄?span style="font-family: 寰蔣闆呴粦, sans-serif;">鐢辯紪璇戝櫒鑷姩鏍規(guī)嵁浼犻掔粰瀹冪殑鍊煎垽鏂?/span></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">variable_name = value;</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">d = 3, f = 5;    // declaration of d and f. Here d and f are int </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">瀵逛簬娌℃湁鍒濆鍖栧畾涔夛細鍏鋒湁闈欐佸瓨鍌ㄦ椂闂村彉閲忕殑闅愬惈闆跺垵濮嬪寲(鎵鏈夊瓧鑺傜殑鍊間負0);鎵鏈夊叾瀹冨彉閲?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">鐨勫垵濮嬪兼槸瀹冧滑鐨勬暟鎹被鍨嬬殑闆跺箋?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>闈欐佺被鍨嬪0鏄?/strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">package main</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">import "fmt"</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">func main() {</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   var x float64</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   x = 20.0</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Println(x)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Printf("x is of type %T ", x)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">}</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">緙栬瘧榪愯緇撴灉鏄細<br /></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">20</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">x is of type float64</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>鍔ㄦ佺被鍨嬪0鏄?綾誨瀷鎺ㄦ柇</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">紺轟緥</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">璇曡瘯涓嬮潰鐨勪緥瀛愶紝鍏朵腑鐨勫彉閲忓凡緇忓0鏄庢病鏈変換浣曠被鍨嬬殑錛屽茍宸茬‘瀹氬湪涓誨嚱鏁頒腑鍒濆鍖栥傚鏋滅被鍨嬫帹鏂殑錛屾垜浠凡緇忓垵濮嬪寲鐨勫彉閲弝浣跨敤:=榪愮畻絎︼紝x鍒濆鍖栦嬌鐢?榪愮畻絎︺?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">package main</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">import "fmt"</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">func main() {</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   var x float64 = 20.0</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   y := 42 </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Println(x)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Println(y)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Printf("x is of type %T ", x)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Printf("y is of type %T ", y)  </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">}</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">緙栬瘧鍜岃繍琛屼笂闈㈢殑紼嬪簭錛岃繖灝嗕駭鐢熶互涓嬬粨鏋滐細</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">20</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">42</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">x is of type float64</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">y is of type int</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;"><strong>娣峰悎鍙橀噺澹版槑</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">涓嶅悓綾誨瀷鐨勫彉閲忓彲浠ヤ竴姝ュ埌浣嶄嬌鐢ㄧ被鍨嬫帹鏂0鏄庛?/p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">package main</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">import "fmt"</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">func main() {</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   var a, b, c = 3, 4, "foo"  </p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Println(a)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Println(b)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Println(c)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Printf("a is of type %T ", a)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Printf("b is of type %T ", b)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">   fmt.Printf("c is of type %T ", c)</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">}</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">緙栬瘧鍜岃繍琛屼笂闈㈢殑紼嬪簭錛岃繖灝嗕駭鐢熶互涓嬬粨鏋滐細</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">3</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">4</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">foo</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">a is of type int</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">b is of type int</p><p style="margin-right: 0px; margin-left: 0px; font-family: 寰蔣闆呴粦; widows: auto;">c is of type string</p><div></div><img src ="http://m.shnenglu.com/zhiyewang/aggbug/213135.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/zhiyewang/" target="_blank">zhiye_wang</a> 2016-03-28 15:33 <a href="http://m.shnenglu.com/zhiyewang/archive/2016/03/28/213135.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Rancher 蹇熶笂鎵嬫寚鍗楁搷浣?1)http://m.shnenglu.com/zhiyewang/archive/2016/03/17/213053.htmlzhiye_wangzhiye_wangThu, 17 Mar 2016 03:03:00 GMThttp://m.shnenglu.com/zhiyewang/archive/2016/03/17/213053.htmlhttp://m.shnenglu.com/zhiyewang/comments/213053.htmlhttp://m.shnenglu.com/zhiyewang/archive/2016/03/17/213053.html#Feedback0http://m.shnenglu.com/zhiyewang/comments/commentRss/213053.htmlhttp://m.shnenglu.com/zhiyewang/services/trackbacks/213053.html闃呰鍏ㄦ枃

]]>
絎洓绔?浣跨敤Docker闀滃儚鍜屼粨搴?浜?http://m.shnenglu.com/zhiyewang/archive/2016/03/17/213052.htmlzhiye_wangzhiye_wangThu, 17 Mar 2016 03:01:00 GMThttp://m.shnenglu.com/zhiyewang/archive/2016/03/17/213052.htmlhttp://m.shnenglu.com/zhiyewang/comments/213052.htmlhttp://m.shnenglu.com/zhiyewang/archive/2016/03/17/213052.html#Feedback0http://m.shnenglu.com/zhiyewang/comments/commentRss/213052.htmlhttp://m.shnenglu.com/zhiyewang/services/trackbacks/213052.html絎洓绔?nbsp;浣跨敤Docker闀滃儚鍜屼粨搴?浜?

鍥為【錛?/strong>

寮濮嬪涔犱箣鍓嶏紝鎴戝厛pull涓嬫潵ubuntu鍜宖edora闀滃儚

[#9#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker pull fedora

Using default tag: latest

latest: Pulling from library/fedora

9bdb5101e5fc: Pull complete 

Digest: sha256:1fa98be10c550ffabde65246ed2df16be28dc896d6e370dab56b98460bd27823

Status: Downloaded newer image for fedora:latest

[#10#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker pull ubuntu

Using default tag: latest

latest: Pulling from library/ubuntu

ebe73f29e6e1: Pull complete 

4976a0f2dc03: Pull complete 

5c117067c385: Pull complete 

001d664e2dd4: Pull complete 

Digest: sha256:7eb6ad74ec4fbe56ac194d8760063c88ca362f05a9038f2bc4f09a51849a4a53

Status: Downloaded newer image for ubuntu:latest

4.5.6 Dockerfile 鍜屾瀯寤虹紦瀛?/strong>

鎯崇暐榪囩紦瀛樺姛鑳斤紝鍙互浣跨敤 docker build 鐨?--no-cache 鏍囧織

sudo docker build --no-cache -t="zhiyewang/static_web" .

4.5.7 鍩轟簬鏋勫緩緙撳瓨鐨?Dockerfile 妯℃澘

FROM ubuntu:14.04

MAINTAINER zhiyewang "zhiye_wang@yeah.net"

ENV REFRESHED_AT 2016-03-16

RUN apt-get -qq update

榪欓噷瑕佹兂閲嶆柊鏋勫緩 Dockerfile 錛屽彧闇瑕佸皢絎笁琛岀殑鏃ユ湡淇敼浠ヤ笅鍗沖彲銆傚皢浼氭洿鏂?APT 鍖呯殑緙?/p>

瀛樸?/p>

4.5.8 鏌ョ湅鏂伴暅鍍?/strong>

鏌ョ湅闀滃儚濡備綍鏋勫緩鍑烘潵錛屽彲浠ヤ嬌鐢?docker history 鍛戒護銆傚彲浠ョ湅鍒版柊鏋勫緩鐨?zhiyewang/stat

 ic_web 闀滃儚鐨勬瘡涓灞傘備互鍙婂垱寤鴻繖浜涘眰鐨?Dcoekrfile 鍛戒護銆?/p>

4.5.9 浠庢瀯寤虹殑鏂伴暅鍍忓惎鍔ㄥ鍣?/p>

涓婁竴鑺傛垚鍔熶嬌鐢?Dockerfile 鍛戒護鏋勫緩鍑?zhiyewang/static_web 榪欎釜闀滃儚銆傜幇鍦ㄦ垜浠潵璇曡瘯

鐪嬮暅鍍忔槸鍚﹀伐浣滄甯搞倆

鍩轟簬鏂版瀯寤虹殑闀滃儚鍚姩涓涓柊瀹瑰櫒銆?/p>

 

[#17#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker run -d -p 80 --name stati

c_web zhiyewang/static_web nginx -g "daemon off;"

d4d9024c688d267761dee792e0b0686a6b2d06dcf53e656c98d95408f4894974

榪欐潯鍛戒護鍩轟簬鏂規(guī)墠鏋勫緩鐨勯暅鍍忓悕瀛楋紝鍚姩浜嗕竴涓悕涓?static_web 鐨勬柊瀹瑰櫒銆?鍚屾椂鎸囧畾浜?-d 閫?/p>

欏癸紝鍛婅瘔 Docker 浠ュ垎紱葷殑鏂瑰紡鍦ㄥ悗鍙拌繍琛屻傚悓鏃朵篃鎸囧畾浜嗗湪鏂板鍣ㄤ腑榪愯鐨勫懡浠? nginx -g "

daemon off;"銆傝繖灝嗕互鍓嶅彴鐨勬柟寮忓惎鍔?Nginx銆傛柊鏍囧織 -p 鐢ㄦ潵鎺у埗 Docker 鍦ㄨ繍琛屾椂搴旇鍏?/p>

寮鍝簺緗戠粶绔彛緇欏閮紙瀹夸富鏈猴級銆?/p>

 

[#19#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker ps -l

CONTAINER ID        IMAGE                            COMMAND                           PORTS                  

d4d9024c688d        zhiyewang/static_web   "nginx -g 'daemon off"         0.0.0.0:32768->80/tcp 

鍙互鐪嬪埌瀹瑰櫒涓殑 80 绔彛琚槧灝勫埌瀹夸富鏈虹殑 32768 绔彛銆?/p>

涔熷彲浠ヤ嬌鐢?docker port 鏌ョ湅绔彛鐨勬儏鍐?/p>

[#20#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker port d4d9024c688d

80/tcp -> 0.0.0.0:32768

榪欐牱鐨勭鍙f槧灝勬柟寮忎負闅忔満鐨勶紝鎴戜滑涔熷彲浠ユ寚瀹氱壒瀹氱殑绔彛鏄犲皠

灝嗗鍣ㄧ殑 80 绔彛緇戝畾鍒版湰鍦板涓繪満鐨?80 绔彛

sudo docker run -d -p 80:80 --name static_web zhiyewang/static_web nginx -g "daemon off;"

灝嗗鍣ㄧ殑 80 绔彛緇戝畾鍒版湰鍦板涓繪満鐨?8080 绔彛

sudo docker run -d -p 8080:80 --name static_web zhiyewang/static_web nginx -g "daemon off;"

灝嗗鍣ㄧ殑 80 绔彛緇戝畾鍒版湰鍦板涓繪満鐨?127.0.0.1 榪欎釜 IP 鐨?80 绔彛

sudo docker run -d -p 127.0.0.1:80:80 --name static_web zhiyewang/static_web nginx -g "daemon off;"

灝嗗鍣ㄧ殑 80 绔彛緇戝畾鍒版湰鍦板涓繪満鐨?127.0.0.1 榪欎釜 IP 鐨勯殢鏈虹鍙?/p>

sudo docker run -d -p 127.0.0.1::80 --name static_web zhiyewang/static_web nginx -g "daemon off;"

瀵瑰鍏紑绔彛錛屾鍛戒護鍙互灝嗗鍣ㄥ唴鐨?80 绔彛瀵規(guī)湰鍦板涓繪満鍏紑錛屽茍涓旂粦瀹氳瀹夸富鏈虹殑涓涓?/p>

闅忔満绔彛銆傛鍛戒護鍚屾椂涔熶細灝?Dockerfile 鏂囦歡涓?EXPOSE 鎸囦護鎸囧畾鐨勫叾浠栫鍙d竴騫跺叕寮銆?/p>

sudo docker run -d -p --name static_web zhiyewang/static_web nginx -g "daemon off;"

榪欐牱鎴戜滑灝卞彲浠ヤ嬌鐢ㄦ湰鍦板涓繪満鐨?IP 鍦板潃鎴栬?127.0.0.1 鐨?localhost 鏉ヨ繛鎺ュ埌榪愯鐨勫鍣紝

鏌ョ湅 Web 鏈嶅姟鍣ㄧ殑鍐呭浜嗐?/p>

[#33#cloudsoar@cloudsoar-virtual-machine ~]$curl localhost:32768

Hi, I am in your container

4.5.10 Dockerfile 鎸囦護

1 CMD 鎸囦護

CMD 鎸囦護鐢ㄤ簬鎸囧畾涓涓鍣ㄥ惎鍔ㄦ椂鍊欓渶瑕佽繍琛岀殑鎸囦護銆傛湁鐐圭被浼間簬 RUN 鎸囦護錛屽尯鍒槸 RUN 

鎸囦護鏄寚瀹氶暅鍍忚鏋勫緩鏃跺欒繍琛岀殑鎸囦護錛岃?CMD 鏄鍣ㄨ鍚姩鏃惰繍琛岀殑鎸囦護銆?/p>

鍛戒護琛屽惎鍔ㄥ鍣ㄧ殑 /bin/true

[#34#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker run -i -t zhiyewang/static_web /bin/true

鍙互浣跨敤 CMD 鍐欏湪 Dockerfile 涓細

CMD ["/bin/true"]

涔熷彲浠ヤ負瑕佽繍琛岀殑鍛戒護鎸囧畾鍙傛暟

CMD ["/bin/bash", "-l"]

闇瑕佹敞鎰忕殑鏄?docker run 鍛戒護鍙互瑕嗙洊 CMD 鎸囦護銆傚鏋?dockerrun 涓寚瀹氫簡鍛戒護錛岃孋M

 D 涓篃鎸囧畾浜嗙浉鍚岀殑鍛戒護錛屽懡浠よ涓殑鎸囦護浼氳鐩?Dockerfile 涓殑 CMD 鎸囦護銆?/p>

鍋囪鎴戜滑鐨?Dockerfile 涓湁濡備笅鍛戒護

CMD [ "/bin/bash" ]

浣跨敤 docker build 鍛戒護鏋勫緩涓涓柊闀滃儚錛屽亣璁句負 zhiyewang/test錛屽茍鍩轟簬姝ら暅鍍忓惎鍔ㄤ竴涓柊

瀹瑰櫒銆?/p>

[#35#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker run -t -i zhiyewang/test

root@7ec0a03d41fc:/# 

鍙互鐪嬪埌 docker run 鍛戒護鐨勬湯灝懼茍娌℃湁鎸囧畾 /bin/bash 鎸囦護錛屽嵈榪涘叆浜嗗鍣ㄧ殑 bash銆傚疄闄呬笂

Docker 浣跨敤浜?CMD 涓寚瀹氱殑鍛戒護銆?/p>

浣嗘槸 Dockerfile 涓彧鑳芥寚瀹氫竴鏉?CMD 鎸囦護銆傚鏋滃埗瀹氬涓紝鍙湁鏈鍚庝竴涓細琚皟鐢ㄣ?/p>

2 ENTRYPOINT

ENTRYPONIT 鎸囦護鎻愪緵鐨勫懡浠や笉浼氬啀瀹瑰櫒鍚姩鏃惰鍛戒護琛岃鐩栥?/p>

ENTRYPONIT ["/usr/sbin/nginx"]

涓?ENTRYPOINT 鎸囧畾鍙傛暟

ENTRYPONIT ["/usr/sbin/nginx", "-g", "daemon off;"]

濡傛灉闇瑕?涔熷彲浠ュ湪榪愯鏃墮氳繃 docker run 鐨?--entrypoint 鏍囧織瑕嗙洊 ENTRYPOINT 鎸囦護銆?/p>

3 WORKDIR

WORKDIR /opt/webapp/db

RUN bundle install

WORKDIR /opt/webapp

ENTRYPOINT [ "rackup" ]

鎶婄洰褰曞垏鎹㈠埌 /opt/webapp/db 鎸囧畾浜?bundle install 鍛戒護錛岀劧鍚庡張灝嗗伐浣滅洰褰曞垏鎹負 /opt

 /webapp 鏈鍚庤繖鍙簡 ENTRYPOINT 鎸囦護鏉ュ惎鍔?rackup 鍛戒護銆?/p>

4 ENV

ENV 鍙互鐢ㄦ潵鍦ㄩ暅鍍忔瀯寤鴻繃紼嬩腑璁劇疆鐜鍙橀噺

ENV RMV_PATH /home/rvm/

榪欎釜鐜鍙橀噺璁劇疆鍚庡湪鍚庣畫鐨勪換浣?RUN 涓兘鍙互浣跨敤

涔熷彲浠ュ湪鍏朵粬鎸囦護涓洿鎺ヤ嬌鐢ㄨ繖浜涚幆澧冨彉閲?nbsp;

RVM_PATH=/home/rvm/ gem install unicorn

ENV 鍒涘緩鐨勭幆澧冨彉閲忎篃浼氳鎸佷箙淇濆瓨鍒頒粠鎴戜滑鐨勯暅鍍忓垱寤虹殑浠諱綍瀹瑰櫒涓傛瘮濡傚湪瀹瑰櫒涓繍琛?/p>

env 鏌ョ湅錛?/p>

root@7ec0a03d41fc:/# env

... 

RVM_PATH=/home/rvm/

榪愯鏃剁幆澧冨彉閲?/p>

sudo docker run -ti -e  "WEB_PORT=8080" ubuntu env

鍙互璁插鍣ㄧ殑 WEB_PORT 鐜鍙橀噺璁劇疆涓?8080

5 USER

user 鎸囦護鐢ㄦ潵鎸囧畾璇ラ暅鍍忎細浠ヤ粈涔堟牱鐨勭敤鎴峰幓鎵ц

USER nginx

鎴戜滑鍙互鎸囧畾鐢ㄦ埛鍚嶆垨鑰?UID 浠ュ強緇勬垨鑰?GID錛岀敋鑷蟲槸涓よ呯殑緇勫悎銆備篃鍙互鍦?docker run 鍛?/p>

浠や腑閫氳繃 -u 閫夐」鏉ヨ鐩栬鎸囦護鐨勫箋傚鏋滀笉閫氳繃 USER 鎸囧畾鐗瑰畾鐢ㄦ埛錛岄粯璁ゆ槸 root 銆?/p>

6 VOLUME

VOLUME ["/opt/project"]

榪欐潯鎸囦護灝嗕細涓哄熀浜庢闀滃儚鍒涘緩鐨勪換浣曞鍣ㄥ垱寤轟竴涓悕涓?/opt/projiect 鐨勬寕杞界偣銆備篃鍙互閫氳繃

鏁扮粍鐨勬柟寮忔寚瀹氬涓嵎銆?/p>

VOLUME ["/opt/project", "/data"]

7 ADD

ADD 鍛戒護鐢ㄦ潵灝嗘瀯寤虹幆澧冧笅鐨勬枃浠跺拰鐩綍澶嶅埗鍒伴暅鍍忎腑銆備篃鍙互鎸囧畾URL銆侱ocker 閫氳繃鐩殑鍦?/p>

鍧鐨勫弬鏁版湯灝劇殑瀛楃鏉ュ垽鏂枃浠舵簮鏄洰褰曡繕鏄枃浠躲傚鏋滅洰鐨勫湴鍧浠?/ 緇撳熬錛孌ocker 璁や負鏄竴涓?/p>

鐩綍錛屽鏋滀笉鏄殑璇濓紝璁や負鏄枃浠躲?/p>

ADD http://wordpress.org/latest.zip /root/wordpress.zip

ADD 鍦ㄥ鐞嗘湰鍦扮殑褰掓。鏂囦歡錛堝寘鎷?gzip錛宐zip2錛寈v錛夋寚瀹氫負婧愭枃浠舵椂鍊欙紝浼氳嚜鍔ㄥ皢褰掓。瑙e帇銆?/p>

ADD latest.tar.gz /var/www/wordpress/

8 COPY

COPY 鍜?ADD 鐨勬湰璐ㄥ尯鍒槸 COPY 鍙叧蹇冨湪鏋勫緩涓婁笅鏂囦腑澶嶅埗鏈湴鏂囦歡錛岃屼笉浼氬幓鍋氭枃浠舵彁

鍙栧拰瑙e帇鐨勫伐浣溿侰OPY 鐨勬枃浠舵簮璺緞蹇呴』鏄竴涓笌褰撳墠鏋勫緩鐜鐩稿鐨勬枃浠舵垨鐩綍錛屾湰鍦版枃

浠墮兘鏀懼埌鍜?Dockerfile 鍚屼竴涓洰褰曚笅銆備笉鑳藉鍒惰鐩綍涔嬪鐨勪換浣曟枃浠躲傜洰鐨勪負姝㈠繀欏繪槸瀹瑰櫒

鍐呴儴鐨勪竴涓粷瀵硅礬寰勩傝鎸囦護鍒涘緩鐨勬枃浠舵垨鑰呯洰褰曠殑 UID 鍜?GID 閮戒細琚緗負 0 銆?/p>

COPY conf.d/ /etc/apache2/

9 ONBUILD

 

4.6 灝嗛暅鍍忛閫佸埌 Docker Hub

[#37#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker push zhiyewang/static_web

The push refers to a repository [docker.io/zhiyewang/static_web] (len: 1)

e97eb7ef0136: Pushed 

6a7a53f6e78a: Pushed 

ddc8935b098a: Pushed 

40fa5cd1c3d2: Pushed 

c5aed3a8ff95: Pushed 

0b427fcc4cbb: Pushed 

9d89fd8f8a3e: Pushed 

073de23ee32b: Pushed 

latest: digest: sha256:152eb2d70e0f795fbe1b8f8c9eea09e7832a8b01e953cc051cd07832732da0ed size: 14731

鐜板湪鍙互鍦?Docker Hub 涓婄湅鍒版垜浠殑闀滃儚浜嗐?/p>

 

鑷姩鏋勫緩

 

4.7 鍒犻櫎闀滃儚

濡傛灉涓嶉渶瑕佷竴涓暅鍍忎簡 鍙互浣跨敤 docker rmi 鏉ュ垹闄?/p>

[#41#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker rmi zhiyewang/static_web

Error response from daemon: conflict: unable to remove repository reference "zhiyewang/static_web" (must force) - container 7ec0a03d41fc is using its referenced image e97eb7ef0136

Error: failed to remove images: [zhiyewang/static_web]

鍙互鐪嬪埌榪欎釜闀滃儚琚竴涓鍣?nbsp;7ec0a03d41fc 浣跨敤鐫錛岄鍏堝垹闄ゆ帀瀹瑰櫒鍗沖彲銆?nbsp;

[#53#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker rm 7ec0a03d41fc

7ec0a03d41fc

[#62#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker rmi e97eb7ef0136

Deleted: e97eb7ef013619e503bd729596a06e46ee85786619d95950e54f5a74c6fc2694

Deleted: 6a7a53f6e78a802ea932a5914e63d217acf4a47ddbedb80dab042d55297573a5

Deleted: ddc8935b098a0b449a3335286b2b0e555b3d44bd5d92dea305c57f6f7c846fae

Deleted: 40fa5cd1c3d2ae9c80763e9b787c5c9b4848a34164fc2138d2c160830505466d

Deleted: c5aed3a8ff9508b42644cef59c2b44c249628c54130fa1a030f3f2b299124ecc

榪欓噷鍒犻櫎鐨勬槸鏈湴鐨勯暅鍍忋傛瘡涓涓?Deleted: 琛岄兘浠h〃涓涓暅鍍忓眰琚垹闄ゃ?/p>

4.8 榪愯鑷繁鐨?Docker Registry

榪欎釜鍙互鑷繁璇曡瘯浜嗐?/p>

 

鍒版涓烘錛岀鍥涚珷瀛︿範瀹屾瘯銆?/p>

涓嬩竴綃囧涔犲湪嫻嬭瘯涓嬌鐢?Docker錛岀敤Docker 嫻嬭瘯涓涓潤鎬佺綉绔欙紝鐢?Docker 鍒涘緩騫舵祴璇曚竴涓?/p>

WEB 搴旂敤錛岀敤 Docker 鐢ㄤ簬鎸佺畫闆嗘垚



]]>
絎洓绔?浣跨敤Docker闀滃儚鍜屼粨搴?/title><link>http://m.shnenglu.com/zhiyewang/archive/2016/03/17/213051.html</link><dc:creator>zhiye_wang</dc:creator><author>zhiye_wang</author><pubDate>Thu, 17 Mar 2016 03:00:00 GMT</pubDate><guid>http://m.shnenglu.com/zhiyewang/archive/2016/03/17/213051.html</guid><wfw:comment>http://m.shnenglu.com/zhiyewang/comments/213051.html</wfw:comment><comments>http://m.shnenglu.com/zhiyewang/archive/2016/03/17/213051.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/zhiyewang/comments/commentRss/213051.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/zhiyewang/services/trackbacks/213051.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>絎?绔?浣跨敤Docker闀滃儚鍜屼粨搴?/strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍥為【錛?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍥為【濡備綍浣跨敤 docker run 鍒涘緩鏈鍩烘湰鐨勫鍣?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">$sudo docker run -i -t --name another_container_mum ubuntu /bin/bash</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">root@3d49f5830c81:/# </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">榪欐潯鍛戒護浼氬惎鍔ㄤ竴涓柊鐨勫悕涓?another_container_mum 鐨勫鍣紝榪欎釜瀹瑰櫒鍩轟簬ubuntu闀?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍍忓茍涓斾細鍚姩Bash Shell</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">---------------------------------------------------------------------------------------------</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>4.1 浠涔堟槸 Docker 闀滃儚</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>4.2 鍒楀嚭闀滃儚</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><img src="http://images2015.cnblogs.com/blog/622771/201603/622771-20160315184735428-1896463575.png" alt="" style="border: 0px; max-width: 900px;" /><br />鍙互鐪嬪嚭鎴戣繖閲屾湁涓変釜闀滃儚銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍏朵腑 ubuntu 鏄垜涓婂崍涓嬭澆鐨?ubuntu 鍩虹闀滃儚錛宲aulcos11/docker-tutorial 鏄笅杞界殑鍙﹀</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">涓涓敤鎴蜂笂浼犵殑闀滃儚銆備絾鏄笉鐭ラ亾 CREATED 榪欎竴鏍忕殑鏃墮棿鎬庝箞涓嶅噯銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">闀滃儚浠庝粨搴撲笅杞戒笅鏉ャ傞暅鍍忎繚瀛樺湪浠撳簱涓傝屼粨搴撳瓨鍦ㄤ簬Registry涓傞粯璁ょ殑Registry鏄敱Do</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">cker鍏徃榪愯惀鐨勫叕鍏?Registry 鏈嶅姟錛屽嵆鏄?Dcoker Hub銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">姣忎釜闀滃儚搴撻兘鍙互瀛樻斁寰堝闀滃儚錛屼緥濡傛垜浠煡鐪嬩竴涓媢buntu浠撳簱涓殑鍏朵粬闀滃儚錛?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍙槸浣跨敤 docker images 鏌ョ湅鎵鏈夌殑 ubuntu docker 闀滃儚</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">sudo docker images</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍙互浣跨敤docker pull涓嬭澆鏌愪釜鍩虹闀滃儚</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[#12#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker pull ubuntu</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Docker Hun 涓湁涓ょ綾誨瀷浠撳簱錛氱敤鎴蜂粨搴撳拰欏跺眰浠撳簱銆傜敤鎴蜂粨搴撶殑闀滃儚閮芥槸鏈塂ocker鐢ㄦ埛</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍒涘緩鐨勶紝鑰岄《灞備粨搴撳垯鏄敱Docker鍐呴儴鐨勪漢鏉ョ鐞嗙殑銆傜敤鎴蜂粨搴撶殑鍛藉悕鐢辯敤鎴峰悕鍜屼粨搴撳悕涓?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">閮ㄥ垎緇勬垚錛屽錛歱aulcos11/docker-tutorial錛岀敤鎴峰悕錛歱aulcos11錛屼粨搴撳悕錛歞ocker-tutor</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">ial錛屼笌鍏剁浉瀵圭殑欏跺眰浠撳簱鍙寘鍚粨搴撳悕閮ㄥ垎錛屼緥濡?ubuntu錛宖edora銆傞《灞備粨搴撶敱Docker鍏?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍙稿拰鐢遍夊畾鐨勮兘鎻愪緵浼樿川鍩虹闀滃儚鐨勫巶鍟嗙鐞嗐?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>4.3 鎷夊彇闀滃儚</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">浣跨敤docker images鍙互鏌ョ湅鏈湴Docker瀹夸富鏈轟笂闈㈢殑闀滃儚銆傚鏋滃笇鏈涜兘鍦ㄩ暅鍍忓垪琛ㄤ腑鍙湅</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍒版煇涓暅鍍忕殑鍐呭錛屼緥濡?fedora錛屽彲浠ラ氳繃鍦?docker images 鍛戒護鍚庨潰璺熸寚瀹氱殑闀滃儚鍚嶆潵瀹?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鐜幫紝渚嬪錛?nbsp;</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><img src="http://images2015.cnblogs.com/blog/622771/201603/622771-20160315184805256-1955200557.png" alt="" style="border: 0px; max-width: 900px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">浣跨敤 docker pull 鎷夊彇闀滃儚</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[#15#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker pull fedora</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Using default tag: latest</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">latest: Pulling from library/fedora</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">6888fc827a3f: Pull complete </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">9bdb5101e5fc: Downloading [===================>                               ] 28.63 MB/74.33 MB</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>4.4 鏌ユ壘闀滃儚</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鎴戞湰鍦扮殑闀滈暅鍍忔湁錛?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[#1#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker images</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[sudo] password for cloudsoar: </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">REPOSITORY                         TAG                 IMAGE ID               CREATED             VIRTUAL SIZE</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">paulcos11/docker-tutorial   latest              e37931352714        8 days ago          587.8 MB</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">ubuntu                                  latest              8ed581e3fa7a        11 days ago         188 MB</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">姝ゆ椂 fedora 闀滃儚榪樻槸娌℃湁涓嬭澆瀹屾瘯鐨勩備笉鐫鎬ャ傛垜浠厛緇冧範鍏朵粬鐨勬搷浣滐紝鍦?nbsp;paulcos11/do</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">cker-tutorial 闀滃儚涓嬌鐢?docker run 鍛戒護鏉ヤ粠 docker-tutorial 鍒涘緩涓涓鍣ㄣ?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[#2#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker run -i -t paulcos11/docker-tutorial /bin/bash</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">root@869a3b2049ad:/#</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍙互鐪嬪埌錛屽凡緇忎粠 paulcos11/docker-tutorial 闀滃儚鍚姩浜嗕竴涓柊鐨勫鍣ㄣ?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>4.5 鏋勫緩闀滃儚</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鏋勫緩 Docker 闀滃儚鏈変互涓嬩袱縐嶆柟娉曪細</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">浣跨敤 docker commit 鍛戒護銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">浣跨敤 docker build 鍛戒護鍜?Dockerfile 鏂囦歡銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>4.5.1 鍒涘緩 Docker Hub 璐﹀彿</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍦?hub.docker.com 鍒涘緩涓涓嚜宸辯殑璐﹀彿錛屾敞鍐屼箣鍚庨氳繃鏀跺埌鐨勭‘璁ら偖浠舵縺媧伙紝涓嬮潰灝卞彲浠ユ祴</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">璇曞垰鎵嶆敞鍐岀殑璐﹀彿鏄惁鍙互宸ヤ綔浜嗐傝鐧誨綍鍒?docker hub錛屽彲浠ヤ嬌鐢?docker login 鍛戒護銆傚</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><img src="http://images2015.cnblogs.com/blog/622771/201603/622771-20160315184831006-1715345304.png" alt="" style="border: 0px; max-width: 900px;" /></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">榪欓噷鐪嬪埌鎴戞槸娉ㄥ唽鎴愬姛浜嗭紝鐢ㄦ埛鍚嶅彧鑳芥槸瀛楁瘝鎴栬呮暟緇勭殑緇勫悎銆備笅闈嬌鐢?docker login 鏉ラ獙璇?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鎴戠殑璐﹀彿錛?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[#4#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker login</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Username: zhiyewang</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Password: </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Email: zhiye_wang@yeah.net           </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">WARNING: login credentials saved in /home/cloudsoar/.docker/config.json</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Login Succeeded</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍙互鐪嬪埌鎴戠殑璐﹀彿鐧誨綍鎴愬姛浜嗐?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>4.5.2 浣跨敤 Docker 鐨?commit 鍛戒護鍒涘緩闀滃儚</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">榪欓噷鎴戝熀浜庡墠闈笅杞界殑 ubuntu 闀滃儚鏉ュ垱寤轟竴涓柊闀滃儚銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">棣栧厛鎴戝湪榪欎釜鍩虹闀滃儚涓惎鍔ㄤ竴涓鍣?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[#5#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker run -i -t ubuntu /bin/bash</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">root@460f5a1ac42a:/# </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍦ㄥ鍣ㄤ腑瀹夎涓?Apache 浣滀負涓涓?web 鏈嶅姟鍣ㄦ潵榪愯銆傝繖鏍鋒瘡嬈′嬌鐢?Apache 鐨勬椂鍊欎笉鐢ㄥ啀</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">閲嶆柊瀹夎 Apache 浜嗐?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">root@460f5a1ac42a:/# apt-get -y install apache2</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Reading package lists... Done</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Building dependency tree       </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">root@460f5a1ac42a:/# apt-get -y install vim</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鎴戝枩嬈㈢敤vim錛屽悓鏃跺張瀹夎浜嗕竴涓?vim錛屽搰鍜斿挃銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">涓轟簡瀹屾垚姝ら」宸ヤ綔錛岄渶瑕佸厛閫鍑?exit 錛岀劧鍚庢墽琛?docker commit 鍛戒護銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">榪欓噷闇瑕佹敞鎰忕殑鏄紝 docker commit 鎻愪氦鐨勬槸鍒涘緩瀹瑰櫒鐨勯暅鍍忎笌瀹瑰櫒鐨勫綋鍓嶇姸鎬佷箣闂存湁宸紓</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鐨勯儴鍒嗭紝榪欎嬌寰楄鏇存柊闈炲父杞婚噺銆傝繖閲屽彲浠ョ湅鍒版垜鍒涘緩鐨勭粨鏋溿?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><img src="http://images2015.cnblogs.com/blog/622771/201603/622771-20160315184856771-1572993164.png" alt="" style="border: 0px; max-width: 900px;" /><br />濡傛灉鍍忎粠鍒氭墠鍒涘緩鐨勯暅鍍忚繍琛屼竴涓鍣紝鍙互浣跨敤 docker run 鍛戒護</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[#16#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker run -t -i zhiyewang/apache2 /bin/bash</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">root@bb634a313bf2:/# </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>4.5.3 浣跨敤 Dockerfile 鏋勫緩闀滃儚</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">浜嬪疄涓婃墍鏈夎祫鏂欓兘涓嶆帹浠嬩嬌鐢?docker commit 鐨勬柟娉曟瀯寤洪暅鍍忥紝鑰屾槸浣跨敤 Dockerfile 鐨勫畾涔?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鏂囦歡鍜?docker build 鍛戒護鏉ユ瀯寤洪暅鍍忋?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>鎴戜滑鐨勭涓涓?Dockerfile</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鐜板湪鎴戜滑鍒涘緩涓涓洰褰曪紝騫跺湪閲岄潰鍒涘緩鍒濆鐨?Dockerfile錛屾垜浠皢鍒涘緩涓涓寘鍚畝鍗?Web 鏈?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鏈嶅姟鍣ㄧ殑 Docker 闀滃儚銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><img src="http://images2015.cnblogs.com/blog/622771/201603/622771-20160315184920428-1804659877.png" alt="" style="border: 0px; max-width: 900px;" /><br />榪欓噷鎴戜滑鍒涘緩浜嗕竴涓悕涓?static_web 鐨勭洰褰曠敤鏉ヤ繚瀛?Dockerfile錛岃繖涓洰褰曞氨鏄垜浠殑鏋勫緩鐜?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">澧冿紙build environment錛夛紝Docker 鍒欑О姝ょ幆澧冧負涓婁笅鏂囷紙context錛夋垨鑰呮瀯寤轟笂涓嬫枃錛坆uild</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> context錛夈侱ocker 浼氬湪鏋勫緩闀滃儚鏃跺欙紝灝嗘瀯寤轟笂涓嬫枃鍜岃涓婁笅鏂囦腑鐨勬枃浠跺拰鐩綍涓婁紶鍒?doc</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ker 瀹堟姢榪涚▼銆傝繖鏍?Docker 瀹堟姢榪涚▼灝辮兘鐩存帴璁塊棶浣犳兂鍦ㄩ暅鍍忎腑瀛樺偍鐨勪換浣曚唬鐮併?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">涓嬮潰鏄竴涓?Dockerfile 鐨勪緥瀛愶紝鐢?Dockerfile 鏋勫緩涓涓兘浣滀負 Web 鏈嶅姟鍣ㄧ殑 Docker 闀滃儚銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">  1 # version: 0.0.1</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">  2 FROM ubuntu:14.04</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">  3 MAINTAINER zhiyewang "zhiye_wang@yeah.net"</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">  4 RUN apt-get update</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">  5 RUN apt-get install -y nginx</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">  6 RUN echo 'Hi, I am in your container' \</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">  7     >/usr/share/nginx/html/index.html</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">  8 EXPOSE 80                             </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍛戒護瑙i噴錛?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Dockerfile 鐢變竴緋誨垪鎸囦護鍜屽弬鏁扮粍鎴愩傛瘡鏉℃寚浠ら兘鏄ぇ鍐欙紝鑰屼笖鍚庨潰闇瑕佽窡涓涓弬鏁般侱ocker</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> file 浼氭寜鐓ч『搴忎粠涓婂線涓嬫墽琛屻?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Dockerfile 鏀寔娉ㄩ噴錛屾墍鏈変互浜曞彿寮澶寸殑閮芥槸娉ㄩ噴銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">FROM ubuntu:14.04 鎸囧畾浜?ubuntu 14.04 浣滀負鍩虹闀滃儚錛屾瘡</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鎵ц涓鏉℃寚浠わ紝瀵瑰鍣ㄥ仛鍑轟慨鏀廣傝嚜鍔ㄤ細鍐嶆寚瀹氱被浼?docker commit 鐨勬搷浣滐紝鎻愪氦涓涓柊闀滃儚</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">灞傦紝緇х畫鎵ц涓嬩竴鏉℃寚浠ゃ?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">MAINTAINER 鎸囦護浼氬憡璇?Docker 璇ラ暅鍍忕殑浣滆呮槸璋侊紝浠ュ強浣滆呯殑鐢?shù)瀛愰偖錃g鍦板潃銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鎺ヤ笅鏉ユ垜浠墽琛屼簡涓夋潯 RUN 鎸囦護錛孯UN 鎸囦護浼氬湪褰撳墠闀滃儚涓繍琛屾寚瀹氱殑鍛戒護銆傛垜浠氳繃RUN鏄?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">浠ゆ洿鏂頒簡 APT 浠撳簱錛屽畨瑁呬簡 nginx 鍖咃紝涔嬪悗鍒涘緩浜? /usr/share/nginx/html/index.html 鏂囦歡錛?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">榛樿鎯呭喌錛孯UN鎵ц浼氬湪 shell 閲屼嬌鐢?/bin/sh -c 鏉ユ墽琛屻傚鏋滃啀涓嶆敮鎸?shell 鎴栬呬笉鎯沖啀 shell</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">涓繍琛岋紝鍙互浣跨敤 exec 鏍煎紡鐨?RUN</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">RUN [ "apt-get", "install", "-y", "nginx" ]</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鎺ヤ笅鏉ョ殑 EXPOSE 鎸囦護錛屽憡璇?Docker 璇ュ鍣ㄥ唴鐨勫簲鐢ㄧ▼搴忓皢浼氫嬌鐢?Docker 鐨勬寚瀹氱鍙c備絾鏄?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Docker 騫朵笉浼氳嚜鍔ㄦ墦寮姝ょ鍙o紝鑰屾槸闇瑕佸啀浣跨敤 docker run 榪愯瀹瑰櫒鏃跺欐寚瀹氶渶瑕佹墦寮閭d簺绔?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍙c?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>4.5.4 鍩轟簬 Dockerfile 鏋勫緩鏂伴暅鍍?/strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">榪愯 Dockerfile </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[#34#cloudsoar@cloudsoar-virtual-machine ~]$cd static_web/</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[#35#cloudsoar@cloudsoar-virtual-machine ~/static_web]$sudo docker build -t="zhiyewang/static_web" .</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Sending build context to Docker daemon 2.048 kB</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Step 1 : FROM ubuntu:14.04</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">14.04: Pulling from library/ubuntu</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Digest: sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Status: Downloaded newer image for ubuntu:14.04</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> 8ed581e3fa7a</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Step 2 : MAINTAINER zhiyewang "zhiye_wang@yeah.net"</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> Running in 7806118624b7</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> c5aed3a8ff95</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Removing intermediate container 7806118624b7</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">...</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Processing triggers for sgml-base (1.26+nmu4ubuntu1) ...</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> ddc8935b098a</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Removing intermediate container c81405d28e41</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Step 5 : RUN echo 'Hi, I am in your container'  >/usr/share/nginx/html/index.html</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> Running in f0049e284208</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> 6a7a53f6e78a</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Removing intermediate container f0049e284208</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Step 6 : EXPOSE 80</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> Running in 2a0714253002</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> e97eb7ef0136</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Removing intermediate container 2a0714253002</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Successfully built e97eb7ef0136</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">榪欓噷浣跨敤 -t 鍙傛暟涓烘柊闀滃儚璁劇疆浜嗕粨搴撳拰鍚嶇О銆備粨搴撲負 zhiyewang錛屽悕縐頒負 static_web錛屼篃鍙?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">浠ユ瀯寤鴻繃紼嬩腑涓洪暅鍍忔坊鍔犱竴涓爣絳撅紝鏂規(guī)硶涓?#8220;闀滃儚鍚嶏細鏍囩”<br />sudo docker build -t="zhiyewang/static_web:v1" .</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">濡傛灉娌℃湁瀹氬埗浠諱綍鏍囩錛孌ocker 浼氳嚜鍔ㄤ負闀滃儚璁劇疆涓涓?latest 鏍囩銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">涓婇潰鍛戒護鏈鍚庣殑 . 鍛婅瘔鎴戜滑鍘誨綋鍓嶈礬寰勫幓鎵?Dockerfile 鏂囦歡銆備篃鍙互鎸囧畾涓涓?Git 浠撳簱鐨勬簮鍦?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍧鏉ユ寚瀹?Dockerfile 鐨勪綅緗備緥濡?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">sudo docker build -t="zhiyewang/static_web:v1" \</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> git@github.com:zhiyewang/docker-static_web</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">榪欓噷鍋囪鐨勫湪 Git 浠撳簱鐨勭洰褰曚笅瀛樺湪 Dockerfile 鏂囦歡銆傛垜涔熸病鏈夋敞鍐?Git 璐﹀彿鍘繪墽琛岃繃銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鏌ョ湅 docker build 榪囩▼鍙戠幇錛屾瀯寤轟笂涓嬫枃宸茬粡涓婁紶鍒頒簡 Docker 瀹堟姢榪涚▼錛?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Sending build context to Docker daemon 2.048 kB</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">涔嬪悗錛屽彲浠ョ湅鍒?Dockerfile 涓殑姣忔潯鏄庝護閮借欏哄簭鎵ц錛岃屼笖鏋勫緩榪囩▼鐨勬渶緇堢粨鏋滆繑鍥炰簡鏂扮殑</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">闀滃儚鐨?ID錛屽嵆 e97eb7ef0136 錛屽茍涓?Docker 浼氭彁浜ゆ瘡涓姝ョ殑鎵ц緇撴灉銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"><strong>4.5.4 鎸囦護澶辮觸鏃跺欎細鎬庢牱</strong></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">渚嬪鎴戜滑灝嗕笂闈㈢殑絎?4 姝ョ殑鍖呭悕 nginx 鍐欐垚 ngin</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[#41#cloudsoar@cloudsoar-virtual-machine ~/static_web]$sudo docker build -t="zhiyewang/static_web" .</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[sudo] password for cloudsoar: </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Sending build context to Docker daemon 2.048 kB</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Step 1 : FROM ubuntu:14.04</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> 8ed581e3fa7a</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Step 2 : MAINTAINER zhiyewang "zhiye_wang@yeah.net"</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> Using cache</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> c5aed3a8ff95</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Step 3 : RUN apt-get update</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> Using cache</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> 40fa5cd1c3d2</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Step 4 : RUN apt-get install -y ngin</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;"> ---> Running in 86e3dbaadf20</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Reading package lists...</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Building dependency tree...</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Reading state information...</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">E: Unable to locate package ngin</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">The command '/bin/sh -c apt-get install -y ngin' returned a non-zero code: 100</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍙戠幇浼氬嚭閿欍傛垜浠潵璋冭瘯涓涓嬪け璐ュ師鍥犮傜敤 docker run 鏄庝護鏉ュ熀浜庤繖嬈℃瀯寤哄埌鐩墠涓烘宸茬粡</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鎴愬姛鐨勬渶鍚庝竴姝ュ垱寤轟竴涓鍣紝瀹冪殑 ID 鏄?nbsp;40fa5cd1c3d2 錛屽涓嬩唬鐮侊細</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">[#42#cloudsoar@cloudsoar-virtual-machine ~/static_web]$sudo docker run -t -i 40fa5cd1c3d2 /bin/bash</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">root@b978996f25f3:/#</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">榪欐椂鎴戜滑鍦ㄦ瀹瑰櫒涓繍琛岀 4 姝ワ細</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">root@b978996f25f3:/# apt-get install -y ngin</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Reading package lists... Done</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Building dependency tree       </p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">Reading state information... Done</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">E: Unable to locate package ngin</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鍙戠幇鍖呭悕閿欒銆?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鎴戜滑鍙互鍦ㄨ繖涓鍣ㄤ腑鍐嶆榪愯 apt-get install -y nginx錛岃繖嬈¤緭鍏ユ紜殑鍖呭悕錛屾潵瀹氫綅闂</p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">錛屽鏋滀竴鏃﹁В鍐充簡榪欎釜闂錛屽氨鍙互閫鍑哄鍣紝鐢ㄦ紜殑鍖呭悕淇敼 Dockerfile 鏂囦歡錛屼箣鍚庡啀嬈?/p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">鏋勫緩鍗沖彲銆?br /><br /></p><p style="margin-top: 10px; margin-bottom: 10px; font-family: Tahoma, Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19.5px; background-color: #e0dfe3;">榪欎竴綃囧埌榪欓噷銆備笅涓綃囩戶緇涔燚ockerfile 鍜屾瀯寤虹紦瀛樸?/p><img src ="http://m.shnenglu.com/zhiyewang/aggbug/213051.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/zhiyewang/" target="_blank">zhiye_wang</a> 2016-03-17 11:00 <a href="http://m.shnenglu.com/zhiyewang/archive/2016/03/17/213051.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>絎笁绔?Docker 鍏ラ棬http://m.shnenglu.com/zhiyewang/archive/2016/03/15/213023.htmlzhiye_wangzhiye_wangTue, 15 Mar 2016 05:43:00 GMThttp://m.shnenglu.com/zhiyewang/archive/2016/03/15/213023.htmlhttp://m.shnenglu.com/zhiyewang/comments/213023.htmlhttp://m.shnenglu.com/zhiyewang/archive/2016/03/15/213023.html#Feedback0http://m.shnenglu.com/zhiyewang/comments/commentRss/213023.htmlhttp://m.shnenglu.com/zhiyewang/services/trackbacks/213023.html絎笁绔?docker 鍏ラ棬

3.1 紜繚docker宸茬粡灝辯華

棣栧厛鏌ョ湅docker紼嬪簭鏄惁瀛樺湪錛屽姛鑳芥槸鍚︽甯?/span>

[#3#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker info

[sudo] password for cloudsoar:

Containers: 11

Images: 16

Server Version: 1.9.1

Storage Driver: aufs

 Root Dir: /var/lib/docker/aufs

 Backing Filesystem: extfs

 Dirs: 38


3.2 榪愯鎴戜滑鐨勭涓涓鍣?/span>

docker run 鍛戒護鎻愪緵浜咲ocker瀹瑰櫒鐨勫垱寤哄埌鍚姩鐨勫姛鑳?/span>

涔︿笂浣跨敤姝ゅ懡浠ゅ垱寤虹涓涓鍣?/span>

[#4#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker run -i -t ubuntu /bin/bash 

 Unable to find image 'ubuntu:latest' locally

latest: Pulling from library/ubuntu

073de23ee32b: Downloading 48.09 MB/65.69 MB

...

鍙互鐪嬪埌鏈夊ぇ姒?6MB錛岀瓑寰呮參鎱笅杞藉畬鎴愩傚叾瀹濽buntu闀滃儚涔熸槸涓涓熀紜闀滃儚銆?/span>

sudo docker run -i -t ubuntu /bin/bash 

榪欏彞鍛戒護鎴戠殑鐞嗚В灝辨槸錛宻udo 涓存椂鍒囨崲綆$悊鍛樻潈闄愶紝浣跨敤 docker run 鍛戒護錛屽惎鍔ㄩ暅鍍?/span>

ubuntu 涓殑 bash銆?/span>docker run 浼氭鏌ユ湰鍦版槸鍚︽湁ubuntu榪欎釜鍩虹闀滃儚錛屽鏋滄病鏈夛紝

鍒欏幓docker hub registry 鍘繪嫻嬪茍涓嬭澆姝ら暅鍍忥紝涓嬭澆瀹屾瘯鍐嶆墽琛屻?/span>

鐢變簬瀹瑰櫒鏈夎嚜宸辯殑ip錛岃嚜宸辯殑shell錛屾槸鐙珛鐨勩傚洜姝ゅ姞涓?-i 鍙傛暟鏉ユ墦寮瀹瑰櫒鐨勬爣鍑嗚緭鍏?/span>

STDIN錛屼嬌鐢?-t 緇欏鍣ㄩ厤涓涓氦浜掑紡緇堢銆傚綋鏂板鍣ㄤ笅杞藉畬姣曞悗錛屼細鑷姩浠oot鐢ㄦ埛鐧?/span>

褰曞埌鏂扮殑瀹瑰櫒涓傜晫闈㈡樉紺虹殑鏄細root@瀹瑰櫒ID 銆傚鍣ㄧ殑涓繪満鍚嶅氨鏄鍣ㄧ殑ID銆?/span>

鍋囪璇存垜浠兂瑕佺粰榪欎釜瀹瑰櫒瀹夎涓涓猚url錛屾垨鑰呮槸 ping錛屽彲浠ラ氳繃濡備笅鍛戒護

sudo docker run ubuntu apt-get install -y curl

docker run 瀹瑰櫒鍚?鍛戒護 


絳変簡鍗婁釜灝忔椂錛岃繕娌′笅杞藉畬姣曪紝鐢變簬榪欎釜鍩虹闀滃儚涓嬭澆瀹炲湪澶參錛屾垜鎹簡涓涓暅鍍?/span>

鎴戜箣鍓峱ull浜嗕竴涓悕涓簆aulcos11/docker-tutorial鐨勯暅鍍忥紝瀹瑰櫒鏈?1涓?/span>

濡傛灉浣犳兂涓嬭澆鍏朵粬鐨勯暅鍍忥紝鍙互浣跨敤 docker search tutorial 棣栧厛鏌ョ湅鍙敤闀滃儚銆傜劧鍚庝嬌鐢?/p>

docker pull 鎶婂畠鎷変笅鏉ャ?/p>

root@cloudsoar-virtual-machine:/home/cloudsoar# docker search tutorial

NAME                                 DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED

georgeyord/reactjs-tutorial          This is the backend of the React comment b...   2                    [OK]

mhausenblas/kairosdb-tutorial        GitHub fetcher for KairosDB tutorial            1                    [OK]

odk211/spree-tutorial                                                                1                    [OK]

paulcos11/docker-tutorial            docker tutorial       


root@cloudsoar-virtual-machine:/home/cloudsoar# docker pull paulcos11/docker-tutorial

Using default tag: latest

latest: Pulling from paulcos11/docker-tutorial

044ffdf80f70: Pull complete 

...

Digest: sha256:8effcf1f4eac7096ba4eaf4a90261580657605d159946372c12ae28b7e5e74f1

Status: Downloaded newer image for paulcos11/docker-tutorial:latest

鍒拌繖閲岋紝鎴戞垚鍔熶笅杞戒簡瀹瑰櫒闀滃儚paulcos11/docker-tutorial


緇х畫嫻佺▼錛岃繘鍏ユ垜浠殑瀹瑰櫒

root@cloudsoar-virtual-machine:~# docker run -i -t paulcos11/docker-tutorial /bin/bash

root@537739299f24:/# 

鎵ц瀹屾瘯鍙互鐪嬪埌榪涘叆浜嗗鍣ㄧ殑bash錛岀敤鎴鋒槸root錛屽鍣↖D鏄?span style="color: #ff0000;">537739299f24錛?/span>


3.3 浣跨敤瀹瑰櫒

鍙互浣跨敤 hostname 鏌ョ湅瀹瑰櫒鐨勪富鏈哄悕

root@537739299f24:/# hostname

537739299f24

鍙互鐪嬪埌瀹瑰櫒鐨処D灝辨槸瀹瑰櫒鐨勪富鏈哄悕銆?br />涓嬩竴姝ョ湅鐪?/etc/hosts 鏂囦歡

root@537739299f24:/# cat /etc/hosts

172.17.0.2 537739299f24

127.0.0.1 localhost

::1 localhost ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

鍙互鐪嬪埌docker 宸茬粡鍦╤ost鏂囦歡涓負璇ュ鍣ㄧ殑ijp澧炲姞浜嗕竴鏉′富鏈洪厤緗」

鍐嶇湅鐪婭P

root@537739299f24:/# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

30: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 

    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff

    inet 172.17.0.2/16 scope global eth0

       valid_lft forever preferred_lft forever

    inet6 fe80::42:acff:fe11:2/64 scope link 

       valid_lft forever preferred_lft forever

鍙互鐪嬪埌榪欓噷鏈塴o鐨勫洖鐜帴鍙c傝繕鏈塱p鏄?72.17.0.2鐨勬爣鍑唀th0鎺ュ彛錛屽拰瀹夸富鏈哄畬鍏ㄤ竴鏍楓?/span>

鏌ョ湅瀹瑰櫒 涓殑榪涚▼

root@537739299f24:/# ps -aux

USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

root          1  0.2  0.1  21944  3528 ?        Ss   03:03   0:01 /bin/bash

root         12  0.0  0.0  19188  2336 ?        R+   03:14   0:00 ps -aux

鎺ヤ笅鏉ワ紝鎴戞兂緇欏鍣ㄥ畨瑁呬竴涓獀im

榪欓噷鎴戝厛鏇存柊涓嬪鍣ㄧ殑婧愬啀瀹夎銆?br />

root@537739299f24:/# apt-get update && apt-get install vim

瀹夎瀹屾瘯浣跨敤 exit錛屽嵆鍙鍑哄埌瀹夸富鏈虹郴緇熴傝繖鏃跺鍣ㄤ篃浼氬仠姝紝鍥犱負涓鏃﹂鍑哄鍣紝

瀹瑰櫒涔熼殢涔嬪仠姝簡榪愯銆備絾鏄鍣ㄤ粛鐒跺瓨鍦紝鍙互鐢?docker ps -a 鏌ョ湅瀹瑰櫒鍒楄〃銆?/span>

root@537739299f24:/# exit

exit

docker ps 鍙互鏌ョ湅榪愯涓殑瀹瑰櫒錛屽姞涓?-a 鍙傛暟鍙互鏌ョ湅鎵鏈夌殑瀹瑰櫒

3.4 瀹瑰櫒鍛藉悕

鍙互浣跨敤濡備笅鍛戒護涓哄鍣ㄦ寚瀹氫竴涓悎娉曟湁鎰忎箟鐨勫悕瀛椼?/p>

root@cloudsoar-virtual-machine:~# docker run --name wzy_the_container -i -t paulcos11/docker-tutorial /bin/bash

root@0a09dfd688ea:/# exit

exit


3.5 閲嶆柊鍚姩宸茬粡鍋滄鐨勫鍣?/span>

姝ゆ椂錛寃zy_the_container 宸茬粡鍋滄浜嗐傚彲浠ヤ嬌鐢ㄥ涓嬪懡浠ら噸鍚竴涓凡緇忓仠姝㈢殑瀹瑰櫒銆?br />

root@cloudsoar-virtual-machine:~# docker start wzy_the_container

wzy_the_container

涔熷彲浠ヤ嬌鐢ㄥ鍣↖D鏇挎崲瀹瑰櫒鍚嶃?/span>


3.6 闄勭潃鍒板鍣ㄤ笂
瀹瑰櫒鍚姩鐨勬椂鍊欎細鎸夌収docker run鎸囧畾鐨勫弬鏁版潵榪愯銆傚洜姝よ繖涓鍣ㄥ惎鍔ㄥ悗浼氬惎鍔ㄤ竴涓氦浜?/p>

鐨剆hell銆傛垜鍙互浣跨敤 docker attach 鐩存帴闄勭潃鍒版瀹瑰櫒銆?/p>

root@cloudsoar-virtual-machine:~# docker attach wzy_the_container

root@0a09dfd688ea:/# 

鍙互鐪嬪埌閲嶆柊浼氬埌浜嗗鍣ㄧ殑Bash鎻愮ず絎︾晫闈€?br />

濡傛灉閫鍑哄鍣ㄧ殑shell錛屽鍣ㄤ篃浼氶殢涔嬪仠姝㈣繍琛屻?/p>


3.7 鍒涘緩瀹堟姢寮忓鍣?/strong>

闄や簡浜や簰寮忚繍琛岀殑瀹瑰櫒錛屾垜浠篃鍙互鍒涘緩瀹堟姢瀹瑰櫒銆傚彲浠ラ暱鏈熺殑榪愯搴旂敤紼嬪簭鎴栬呮湇鍔°?/p>

澶у鏃跺欓渶瑕佸垱寤哄畧鎶ゅ紡瀹瑰櫒銆?/p>

[#10#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker run --name daemon_dave -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"

cf5636f0499fa0105b845b5dfa61913ff7d5fccfb1b19c16b09ed2752233794d

鐢變簬姝ゆ椂絎?3.2 姝ユ垜涓嬭澆鐨?Ubuntu 鍩虹闀滃儚Downloading 48.09 MB/65.69 MB 鍒氬ソ涓嬭澆

瀹屾瘯錛屾墍浠ユ鏃舵垜寮濮嬩嬌鐢╱buntu瀹瑰櫒闀滃儚鎿嶄綔浜嗐?/span>

docker run 鐨勫弬鏁?-d 鏄斁鍒板悗鍙版墽琛屻傛鏃舵垜浠茍娌℃湁鍍忎笂涓涓鍣ㄧ洿鎺ラ檮鐫鍒版柊瀹瑰櫒鐨?/span>

shell浼氳瘽涓婏紝鑰屾槸榪斿洖浜嗕竴涓鍣↖D鑰屽凡銆傛鏃朵嬌鐢?docker ps 鍙互鐪嬪埌姝e湪榪愯鐨勫鍣ㄣ?/span>


ubuntu灝辨槸鎴戝垰鍒氫笅杞藉畬姣曠殑鍩虹闀滃儚銆?paulcos11/docker-tutorial 鏄垜鑷繁涓嬭澆鐨勫叾浠栫殑闀滃儚銆?br />

3.8 瀹瑰櫒鍐呴儴鍐嶆悶浠涔?/strong>

浣跨敤 docker logs 鑾峰彇瀹瑰櫒鏃ュ織

[#16#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker logs daemon_dave

hello world

hello world

hello world

hello world

hello world

hello world

鎴栬呭彲浠ュ姞涓?f 瀹炴椂鐩戞帶瀹瑰櫒鏃ュ織銆?/span>

sudo docker logs -f daemon_dave

涔熷彲浠ヨ拷韙棩蹇楁煇涓鐗囨錛屽彧闇瑕乼ail鍛戒護鍔犲叆 -f --lines鏍囧織鍗沖彲銆?/p>

渚嬪錛?docker logs --tail 10 daemon_dave 鑾峰彇鏈鍚?0琛屾棩蹇楀嵆鍙?/p>

 docker logs --tail 0 -f daemon_dave 鑾峰彇鏈鏂版棩蹇椼?/p>

濡傛灉瑕佹煡鐪嬫棩蹇楃殑鏃墮棿錛屽彲浠ュ姞涓婃椂闂存埑銆?/p>

[#18#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker logs -ft daemon_dave

2016-03-15T03:45:28.457991514Z hello world

2016-03-15T03:45:29.472422582Z hello world

2016-03-15T03:45:30.475130491Z hello world


3.9 鏌ョ湅瀹瑰櫒榪涚▼

鏌ョ湅瀹瑰櫒鍐呯殑榪涚▼鍙互浣跨敤 docker top 鍛戒護銆?br />

[#20#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker top daemon_dave

UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD

root                25381               22325               0                   11:45               ?                   00:00:00            /bin/sh -c while true; do echo hello world; sleep 1; done


3.10 鍦ㄥ鍣ㄥ唴閮ㄨ繍琛岃繘紼?/span>

鎴戜滑鍙互浣跨敤docker exec 鍛戒護鍦ㄥ鍣ㄥ唴閮ㄩ澶栧惎鍔ㄦ柊榪涚▼錛屽彲浠ヨ繍琛岀殑榪涚▼鏈変袱縐嶇被鍨嬶紝

浜や簰寮忎換鍔″拰鍚庡彴浠誨姟銆傞鍏堟垜浠嬌鐢?touch 鍛戒護鍒涘緩涓涓┖鏂囦歡銆?/span>

$sudo docker exec -d daemon_dave touch /etc/new_config_file

-d 琛ㄧず鏄悗鍙拌繘紼嬨?/span>

鎴栬呮墦寮涓涓猻hell

$sudo docker exec -t -i daemon_dave /bin/bash

root@cf5636f0499f:/#


3.11 鍋滄瀹堟姢寮忓鍣?/span>

$sudo docker stop daemon_dave

daemon_dave


3.12 鑷姩閲嶅惎瀹瑰櫒

濡傛灉鐢變簬鏌愮閿欒瀵艱嚧瀹瑰櫒鍋滄錛屽彲浠ラ氳繃 --restart 鏍囧織璁ヾocker鑷姩閲嶆柊鍚姩瀹瑰櫒銆?/span>

$sudo docker run --restart=on-failure:5 --name daemon_dave -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"

Error response from daemon: Conflict. The name "daemon_dave" is already in use by container cf5636f0499f. You have to remove (or rename) that container to be able to reuse that name.

榪欓噷鎴戠殑榪愯涓嶈搗鏉ワ紝鍥犱負 -- restart 鏍囩ず鏄痙ocker 2.0 寮曞叆鐨勩傛垜鐨勬槸docker 1.9鐗堟湰銆?/p>


3.13 娣卞叆瀹瑰櫒

闄や簡浣跨敤docker ps 鏌ョ湅瀹瑰櫒淇℃伅錛岃繕鍙互浣跨敤 docker inspect 鏌ョ湅鏇村淇℃伅


$sudo docker inspect daemon_dave

[sudo] password for cloudsoar:

[

{

    "Id": "cf5636f0499fa0105b845b5dfa61913ff7d5fccfb1b19c16b09ed2752233794d",

    "Created": "2016-03-15T03:45:28.124542139Z",

    "Path": "/bin/sh",

    "Args": [

        "-c",

        "while true; do echo hello world; sleep 1; done"

    ],

    "State": {

        "Status": "exited",

        "Running": false,

        "Paused": false,

        "Restarting": false,

        "OOMKilled": false,

        "Dead": false,

        "Pid": 0,

        "ExitCode": 137,

        "Error": "",

        "StartedAt": "2016-03-15T03:45:28.455126857Z",

        "FinishedAt": "2016-03-15T04:05:11.945521026Z"

    },

   ...

涔熷彲浣跨敤 -f 鎴栬?--format 鏍囧織鏉ラ夊畾鏌ョ湅緇撴灉銆?/p>

$sudo docker inspect --format='{{ .State.Running}}' daemon_dave

false

浠ュ強鏌ョ湅鍏朵粬淇℃伅

$sudo docker start daemon_dave

daemon_dave

$sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' daemon_dave

172.17.0.3


3.14 鍒犻櫎瀹瑰櫒

濡傛灉瀹瑰櫒涓嶅湪浣跨敤錛屽彲浠ヤ嬌鐢?docker rm 鍛戒護鍒犻櫎銆?/span>

榪欓噷鍋囪鎴戣鍒犻櫎 daemon_dave 榪欎釜瀹瑰櫒錛屼粬鐨勫鍣↖D鏄?nbsp;cf5636f0499f

$sudo docker rm cf5636f0499f

Error response from daemon: Conflict, You cannot remove a running container. Stop the container before attempting removal or use -f

Error: failed to remove containers: [cf5636f0499f]

$sudo docker stop cf5636f0499f

cf5636f0499f

$sudo docker rm cf5636f0499f

cf5636f0499f

鐢變簬涓嶈兘鍒犻櫎姝e湪榪愯鐨勫鍣紝鎵浠ラ渶瑕佸厛鍋滄銆?/p>


3.15 灝忕粨

涓嬩竴绔犲涔犲浣曟瀯寤鴻嚜宸辯殑Docker闀滃儚錛屼互鍙婂浣曚嬌鐢―ocker 浠撳簱鍜?Docker Registry.



]]>
絎簩绔?Docker 瀹夎絎旇http://m.shnenglu.com/zhiyewang/archive/2016/03/14/213014.htmlzhiye_wangzhiye_wangMon, 14 Mar 2016 10:00:00 GMThttp://m.shnenglu.com/zhiyewang/archive/2016/03/14/213014.htmlhttp://m.shnenglu.com/zhiyewang/comments/213014.htmlhttp://m.shnenglu.com/zhiyewang/archive/2016/03/14/213014.html#Feedback0http://m.shnenglu.com/zhiyewang/comments/commentRss/213014.htmlhttp://m.shnenglu.com/zhiyewang/services/trackbacks/213014.html2.1 瀹夎 Docker 鐨勫厛鍐蟲潯浠?/p>

榪愯 64 浣?CPU 鏋舵瀯鐨勮綆楁満錛孌ocker 鐩墠涓嶆敮鎸?32 浣?CPU

榪愯 Linux 3.8 鎴栬呮洿楂樼増鏈唴鏍搞?/p>

鍐呮牳蹇呴』鏀寔涓縐嶉傚悎鐨勫瓨鍌ㄩ┍鍔?(storage driver)錛屼緥濡?Device Mapper, AUFS

鍐呮牳蹇呴』鏀寔騫跺紑鍚?cgroup 鍜屽懡鍚嶇┖闂?(namespace) 鍔熻兘

2.2 Ubuntu 涓畨瑁?Docker

瀹樻柟鏀寔鐗堟湰錛?/p>

Ubuntu Trusty 14.04 LTS 64 浣?/p>

Ubuntu Precise 12.04 LTS 64 浣?/p>

浣嗘槸騫朵笉鎰忓懗鐫鍏朵粬鐨刄buntu鎴栬匘ebian鐗堟湰灝變笉鑳藉畨瑁匘ocker錛屽彧瑕佹湁鍚堥傜殑鍐呮牳鍜?/p>

Docker鎵蹇呴』鐨勬敮鎸佸嵆鍙?/p>

2.2.1 媯鏌ュ墠鎻愭潯浠?/p>

# 鎴戠殑鐜鏄?windows 7 鏃楄埌鐗?64 浣嶏紝 6GB 鍐呭瓨銆?/p>

# 瀹夎浜?Vmware 铏氭嫙鏈猴紝閲岄潰瀹夎浜嗕竴涓?Ubuntu 15.10 

Technorati 鏍囪:
[#1#cloudsoar@cloudsoar-virtual-machine ~]$uname -a
Linux cloudsoar-virtual-machine 3.19.0-15-generic #15-Ubuntu SMP Thu Apr 16 23:32:37 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

鍙互鐪嬪埌鎴戠殑鍐呮牳鏄?3.19.0 x86_64 鐨勫唴鏍革紝鍥犳涓嶉渶瑕佸崌綰у唴鏍?/p>

2 鏌ョ湅Device Mapper

浠諱綍 Ubuntu 12.04 鎴栬呮洿楂樼増鏈兘宸茬粡瀹夎浜咲evice Mapper錛屽涓嬪懡浠ゅ彲浠ョ‘璁ゆ槸鍚﹀畨瑁?/p>

[#2#cloudsoar@cloudsoar-virtual-machine ~]$ls -l /sys/class/misc/device-mapper lrwxrwxrwx 1 root root 0  3鏈?14 15:26 /sys/class/misc/device-mapper -> ../../devices/virtual/misc/device-mapper 

2.2.2 瀹夎 Docker

棣栧厛闇瑕佹坊鍔?Docker 鐨?APT 浠撳簱錛屾坊鍔犱箣鍓嶉渶瑕佺‘璁ゅ凡緇忓畨瑁呬簡curl鍛戒護

[#3#cloudsoar@cloudsoar-virtual-machine ~]$whereis curl curl: /usr/bin/curl /usr/share/man/man1/curl.1.gz [#4#cloudsoar@cloudsoar-virtual-machine ~]$sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" 

濡傛灉娌″畨瑁咃紝浣跨敤 apt-get –y install curl 鍛戒護瀹夎

鎺ヤ笅鏉ユ坊鍔?Docker 浠撳簱鐨?GPG 瀵嗛挜

[#7#cloudsoar@cloudsoar-virtual-machine ~]$curl -s https://get.docker.io/gpg | sudo apt-key add - gpg: 鎵句笉鍒版湁鏁堢殑 OpenPGP 鏁版嵁銆?/pre> 

鎴戠殑铏氭嫙鏈烘槸浠婂ぉ瀹夎鐨勬柊鐨勩傝繖閲屾彁紺烘姤閿欙紝鎵句笉鍒癘penPGP鏁版嵁銆?/p>

緗戜笂宸壘鍒版柟娉曪細

[#10#cloudsoar@cloudsoar-virtual-machine ~]$sudo curl -s https://get.docker.io/gpg | sudo apt-key add - gpg: 鎵句笉鍒版湁鏁堢殑 OpenPGP 鏁版嵁銆?[#11#cloudsoar@cloudsoar-virtual-machine ~]$gpg --keyserver pgpkeys.mit.edu --recv-key 9AA38DCD55BE302B gpg: 宸插垱寤虹洰褰?#8216;/home/cloudsoar/.gnupg’ gpg: 鏂扮殑閰嶇疆鏂囦歡‘/home/cloudsoar/.gnupg/gpg.conf’宸插緩绔?gpg: 璀﹀憡錛氬湪‘/home/cloudsoar/.gnupg/gpg.conf’閲岀殑閫夐」浜庢嬈¤繍琛屾湡闂存湭琚嬌鐢?gpg: 閽ュ寵鐜?#8216;/home/cloudsoar/.gnupg/secring.gpg’宸插緩绔?gpg: 閽ュ寵鐜?#8216;/home/cloudsoar/.gnupg/pubring.gpg’宸插緩绔?gpg: 涓嬭澆瀵嗛挜‘55BE302B’錛屼粠 hkp 鏈嶅姟鍣?pgpkeys.mit.edu gpg: /home/cloudsoar/.gnupg/trustdb.gpg錛氬緩绔嬩簡淇′換搴︽暟鎹簱 gpg: 瀵嗛挜 55BE302B錛氬叕閽?#8220;Debian Archive Automatic Signing Key (5.0/lenny) <ftpmaster@debian.org>”宸插鍏?gpg: 娌℃湁鎵懼埌浠諱綍緇濆淇′換鐨勫瘑閽?gpg: 鍚堣琚鐞嗙殑鏁伴噺錛? gpg:               宸插鍏ワ細1  (RSA: 1) [#12#cloudsoar@cloudsoar-virtual-machine ~]$gpg -a --export  9AA38DCD55BE302B | sudo apt-key add - OK 

瀹屾垚鍚庢洿鏂版簮錛宻udo apt-get update

姝ゆ椂錛屾垜鐢ㄨ櫄鎷熸満鍒涘緩浜嗕竴涓揩鐓у浠斤紝浠ヤ究浠ュ悗鏈夐棶棰橀渶瑕佹仮澶嶇殑鏃跺欐柟渚夸嬌鐢ㄣ?/p>

涓嬮潰寮濮嬪畨瑁匘ocker

[#14#cloudsoar@cloudsoar-virtual-machine ~]$sudo apt-get install lxc-docker 姝e湪璇誨彇杞歡鍖呭垪琛?.. 瀹屾垚 姝e湪鍒嗘瀽杞歡鍖呯殑渚濊禆鍏崇郴鏍?姝e湪璇誨彇鐘舵佷俊鎭?.. 瀹屾垚 灝嗕細瀹夎涓嬪垪棰濆鐨勮蔣浠跺寘錛?  aufs-tools cgroupfs-mount git git-man liberror-perl lxc-docker-1.9.1 寤鴻瀹夎鐨勮蔣浠跺寘錛?  git-daemon-run git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch   git-cvs git-mediawiki git-svn 涓嬪垪銆愭柊銆戣蔣浠跺寘灝嗚瀹夎錛?  aufs-tools cgroupfs-mount git git-man liberror-perl lxc-docker lxc-docker-1.9.1 鍗囩駭浜?0 涓蔣浠跺寘錛屾柊瀹夎浜?7 涓蔣浠跺寘錛岃鍗歌澆 0 涓蔣浠跺寘錛屾湁 322 涓蔣浠跺寘鏈鍗囩駭銆?闇瑕佷笅杞?12.1 MB 鐨勮蔣浠跺寘銆?瑙e帇緙╁悗浼氭秷鑰楁帀 53.8 MB 鐨勯澶栫┖闂淬?鎮(zhèn)ㄥ笇鏈涚戶緇墽琛屽悧錛?[Y/n] y 

鏁翠釜涓嬭澆榪囩▼鍙兘鏈夌偣鎱紝鎴戣繖閲屾槸鐢?shù)淇?00Mb鐨勫厜綰わ紝涓嬭澆閫熷害鏄?0kb/s宸﹀彸

瀹夎瀹屾瘯鍚庯紝浣跨敤 docker info 鏌ョ湅鏄惁瀹夎騫惰繍琛屼簡

[#15#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker info Containers: 0 Images: 0 Server Version: 1.9.1 Storage Driver: aufs  Root Dir: /var/lib/docker/aufs  Backing Filesystem: extfs  Dirs: 0  Dirperm1 Supported: true Execution Driver: native-0.2 Logging Driver: json-file Kernel Version: 3.19.0-15-generic Operating System: Ubuntu 15.04 CPUs: 1 Total Memory: 2.43 GiB Name: cloudsoar-virtual-machine ID: RL5D:42DH:XMAC:GDQY:VWPJ:3YGM:UHQK:K3QD:USCH:TEGA:32PF:HUNB 

2.2.3 Docker 鍜?UFW

ubuntu涓紝濡傛灉浣跨敤 UFW (Uncomplicated Firewall) 榪橀渶瑕佸惎鍔?UFW 鐨勬暟鎹寘杞彂

Docker鎵嶈兘姝e父榪愯錛岄渶瑕佸 /etc/default/uwf 鏂囦歡鍋氬嚭涓鐐規(guī)敼鍔?/p>

灝?DEFAULT_FORWARD_POLICY="DROP" 鏀逛負 “ACCEPT”, 淇濆瓨浠庢柊鍔犺澆鍗沖彲.

2.9 Docker 瀹堟姢榪涚▼

褰?Docker 瀹夎瀹屾瘯鍚? 榛樿浼氱珛鍗沖惎鍔?Docker 瀹堟姢榪涚▼. 鐩戝惉 /var/run/docker.sock 榪?/p>

涓?Unix 濂楁帴瀛楁枃浠舵潵鑾峰彇鏉ヨ嚜瀹㈡埛绔殑 Docker 璇鋒眰. 濡傛灉緋葷粺瀛樺湪鍚嶄負 docker 鐨勭敤鎴風粍

鐨勮瘽錛孌ocker 浼氬皢姝ゅ鎺ュ瓧鏂囦歡鐨勬墍鏈夎呰緗負 docker 鐢ㄦ埛緇勶紝榪欐牱 docker 鐢ㄦ埛緇勬墍

鏈夌敤鎴烽兘鍙互鐩存帴榪愯 Docker 涓嶇敤浣跨敤 sudo銆?/p>

2.9.1 閰嶇疆 Docker 瀹堟姢榪涚▼

[#19#cloudsoar@cloudsoar-virtual-machine ~]$sudo /usr/bin/docker -d -H tcp://0.0.0.0:2375
榪欐潯鍛戒護浼氬皢Docker瀹堟姢榪涚▼緇戝畾鍒板涓繪満涓婄殑鎵鏈夌綉緇滄帴鍙c?

2.9.2 媯鏌ュ畧鎶よ繘紼嬫槸鍚﹀湪榪愯

[#2#cloudsoar@cloudsoar-virtual-machine ~]$sudo status docker [sudo] password for cloudsoar:  status: 鏃犳硶榪炴帴鍒?Upstart: Failed to connect to socket /com/ubuntu/upstart: 鎷掔粷榪炴帴 
鎴戣繖閲屾姤閿欍?

浠婂ぉ鏆傛椂榪樻湭瑙e喅錛屾湁寰呰繘涓姝ユ煡鎵捐祫鏂欍?/p>

]]> 青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              中国亚洲黄色| 一区二区精品在线观看| 国产精品久久一区二区三区| 小处雏高清一区二区三区| 一本久久青青| aa成人免费视频| 一区二区冒白浆视频| 亚洲精品国产精品久久清纯直播| 欧美一区激情| 久久久水蜜桃av免费网站| 久久尤物视频| 亚洲缚视频在线观看| 亚洲日本欧美| 亚洲免费在线观看| 午夜一区二区三区不卡视频| 久久激情婷婷| 欧美成人综合| 国产精品香蕉在线观看| 永久免费精品影视网站| 99国产精品一区| 亚洲午夜精品一区二区三区他趣| 久久福利影视| 老鸭窝毛片一区二区三区| 欧美激情视频在线免费观看 欧美视频免费一 | 久久亚洲美女| 女人色偷偷aa久久天堂| 亚洲国产精品va| 亚洲无吗在线| 久久夜色精品国产欧美乱极品| 久久久久国产精品www | 欧美日韩成人免费| 国产亚洲欧美日韩精品| 亚洲精品一区二区三区婷婷月| 午夜精品三级视频福利| 欧美成人免费在线观看| 亚洲视频一二| 欧美成人精品一区二区三区| 一区二区三区产品免费精品久久75 | 亚洲国产欧美另类丝袜| 亚洲午夜av| 久久综合给合| 亚洲最新视频在线| 久久亚洲国产精品日日av夜夜| 欧美三区在线视频| 亚洲激情六月丁香| 亚洲欧美国产视频| 亚洲欧洲日本国产| 久久久久九九视频| 国产日本欧洲亚洲| 日韩视频二区| 亚洲第一黄网| 久久精品中文字幕免费mv| 国产精品亚洲美女av网站| av成人手机在线| 亚洲激情在线观看| 美女脱光内衣内裤视频久久影院| 国产日韩视频一区二区三区| 亚洲免费伊人电影在线观看av| 亚洲电影在线| 免费成人美女女| 亚洲国产视频一区| 欧美成人资源| 欧美成人一区二区三区片免费| 亚洲国产成人午夜在线一区| 免费视频最近日韩| 久久综合久久久久88| 在线欧美视频| 亚洲国产99| 欧美日产在线观看| 国产精品久久久对白| 亚洲国产精品日韩| 激情综合色综合久久| 在线观看一区| 久久成人久久爱| 亚洲图片激情小说| 国产精品久久久久三级| 亚洲精品少妇30p| 久久综合久久综合这里只有精品 | 国产精品免费看| 亚洲福利视频免费观看| 欧美jizzhd精品欧美巨大免费| 欧美在线视频免费| 国产亚洲网站| 久久久久亚洲综合| 久久精品99国产精品| 在线观看日韩精品| 亚洲精品视频一区| 国产精品欧美日韩一区| 亚洲欧美卡通另类91av| 欧美在线播放高清精品| 激情欧美一区| 欧美激情bt| 欧美日韩网址| 亚洲欧美成人网| 久久国产精品高清| 精品91视频| 亚洲巨乳在线| 国产精品久久久亚洲一区| 午夜精品影院| 久久亚洲免费| 亚洲视频精选在线| 久久激情网站| 亚洲精选中文字幕| 日韩一级黄色大片| 精品动漫3d一区二区三区免费版 | 欧美日韩亚洲另类| 久久人体大胆视频| 欧美午夜不卡影院在线观看完整版免费| 欧美一区二区免费视频| 美女日韩在线中文字幕| 性欧美激情精品| 欧美激情网友自拍| 久久精品国产v日韩v亚洲| 欧美成人一区二区在线| 久久精品男女| 欧美午夜电影在线| 亚洲黄色一区二区三区| 激情久久久久久久久久久久久久久久| 亚洲乱码视频| 亚洲日本aⅴ片在线观看香蕉| 亚洲曰本av电影| 欧美伦理a级免费电影| 欧美日韩一区二区在线观看视频| 久久久国产精彩视频美女艺术照福利| 欧美精品v日韩精品v韩国精品v| 久久人人97超碰国产公开结果| 国产精品国产自产拍高清av| 亚洲激情成人| 91久久精品国产91性色| 久久国产一区二区三区| 欧美怡红院视频| 国产精品美女久久久久aⅴ国产馆| 亚洲欧洲日产国产综合网| 在线精品视频一区二区| 欧美在线91| 久久精品二区| 国产欧美一区二区三区久久 | 一区二区三区蜜桃网| 一本久道综合久久精品| 欧美国产成人在线| 亚洲国产天堂网精品网站| 91久久久久久| 欧美福利网址| 亚洲区一区二| 99riav久久精品riav| 欧美成人精品高清在线播放| 欧美激情一区二区三区高清视频 | 亚洲欧美日韩精品久久亚洲区 | 久久精品国产免费观看| 国产精品日本一区二区| 亚洲一区二区三区免费视频| 午夜精品成人在线| 国产精品视频网站| 亚洲欧美在线免费观看| 久久国产精品一区二区三区四区 | 久久gogo国模啪啪人体图| 国产精品yjizz| 亚洲女人天堂成人av在线| 欧美在线精品一区| 激情综合激情| 欧美—级在线免费片| 一区二区日韩精品| 欧美一区二区三区在线看| 韩日精品中文字幕| 美女露胸一区二区三区| 一区二区欧美日韩视频| 久久成人亚洲| 亚洲日本欧美| 国产精品视频xxxx| 久久精品免费看| 亚洲精品久久久久久久久久久久久| 一区二区三区高清不卡| 国产九九精品| 欧美成人中文| 亚洲欧美中文日韩在线| 亚洲大片精品永久免费| 亚洲欧美另类综合偷拍| 国内精品视频666| 欧美日韩成人在线观看| 欧美国产精品va在线观看| 亚洲一区二区在线| 久久久久国内| 日韩一区二区精品在线观看| 国产精品爽黄69| 美女999久久久精品视频| 一本久久综合亚洲鲁鲁| 麻豆精品国产91久久久久久| 中文日韩在线视频| 在线播放豆国产99亚洲| 欧美亚韩一区| 欧美激情二区三区| 久久激情综合网| 一区二区三区四区国产精品| 欧美成人国产| 久久久999精品免费| 在线亚洲精品| 91久久在线视频| 精品成人国产在线观看男人呻吟| 欧美调教视频| 欧美绝品在线观看成人午夜影视|