-
Notifications
You must be signed in to change notification settings - Fork 0
/
local-search.xml
121 lines (58 loc) · 58 KB
/
local-search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>tailwindcss教程(4):Flex布局</title>
<link href="/2020-05-31/ckaxfq6vz000210qshry233la.html"/>
<url>/2020-05-31/ckaxfq6vz000210qshry233la.html</url>
<content type="html"><![CDATA[<p><img src="https://mmbiz.qpic.cn/mmbiz_gif/6aVaON9Kibf5ibKRPQgZ9XgbVNsIeQUnfKy4ia9OoKXgFWC78shRtzFR8icyLGazjnMGfyME6zwiadltkTakg8V0icag/640?" srcset="/img/loading.gif" alt=""></p><blockquote><p>我没有失败5000次,是成功了5000次,我成功的证明了哪些方法是行不通的。</p></blockquote><p><img src="https://mmbiz.qpic.cn/mmbiz_gif/yIGVCsrQyYJHvJUMS22qwaDJM2sbtdjc8SdOkeT47kLx1b7j1Xsco5KgiarichObx7dCgiaLdjDjcPvYdoFKob6WQ/640" srcset="/img/loading.gif" alt=""></p><p>正文共:4039字 15图<br>预计阅读时间:11分钟</p><h1 id="什么是Flex布局?"><a href="#什么是Flex布局?" class="headerlink" title="什么是Flex布局?"></a>什么是Flex布局?</h1><blockquote><p>Flex是Flexible Box的缩写,顾名思义为“弹性布局”,用来为盒装模型提供最大的灵活性。 </p></blockquote><pre><code class="hljs css"><span class="hljs-selector-class">.flex</span> { <span class="hljs-attribute">display</span>: flex}<span class="hljs-selector-class">.sm</span>\<span class="hljs-selector-pseudo">:flex</span> { <span class="hljs-attribute">display</span>: flex }<span class="hljs-selector-class">.md</span>\<span class="hljs-selector-pseudo">:flex</span> { <span class="hljs-attribute">display</span>: flex } <span class="hljs-selector-class">.lg</span>\<span class="hljs-selector-pseudo">:flex</span> { <span class="hljs-attribute">display</span>: flex } <span class="hljs-selector-class">.xl</span>\<span class="hljs-selector-pseudo">:flex</span> { <span class="hljs-attribute">display</span>: flex }</code></pre><ul><li>后续如果媒体查询如无差异的源码将不再重复贴出。 </li><li>采用Flex布局的元素,称为Flex容器(flex container),简称“容器”。它的所有子元素自动成为容器成员,成为flex项目(flex item),简称“项目”。</li></ul><table><thead><tr><th>Class</th><th>Properties</th></tr></thead><tbody><tr><td>.flex-initial</td><td>flex: 0 1 auto;</td></tr><tr><td>.flex-1</td><td>flex: 1 1 0%;</td></tr><tr><td>.flex-auto</td><td>flex: 1 1 auto;</td></tr><tr><td>.flex-none</td><td>flex: none;</td></tr></tbody></table><table><thead><tr><th>Class</th><th>Properties</th></tr></thead><tbody><tr><td>.flex-grow</td><td>flex-grow: 1;</td></tr><tr><td>.flex-grow-0</td><td>flex-grow: 0;</td></tr></tbody></table><table><thead><tr><th>Class</th><th>Properties</th></tr></thead><tbody><tr><td>.flex-shrink</td><td>flex-shrink: 1;</td></tr><tr><td>.flex-shrink-0</td><td>flex-shrink: 0;</td></tr></tbody></table><pre><code class="hljs css"><span class="hljs-selector-class">.flex-1</span> { <span class="hljs-attribute">flex</span>: <span class="hljs-number">1</span> <span class="hljs-number">1</span> <span class="hljs-number">0%</span>}<span class="hljs-selector-class">.flex-auto</span> { <span class="hljs-attribute">flex</span>: <span class="hljs-number">1</span> <span class="hljs-number">1</span> auto}<span class="hljs-selector-class">.flex-initial</span> { <span class="hljs-attribute">flex</span>: <span class="hljs-number">0</span> <span class="hljs-number">1</span> auto}<span class="hljs-selector-class">.flex-none</span> { <span class="hljs-attribute">flex</span>: none}<span class="hljs-selector-class">.flex-grow-0</span> { <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">0</span>}<span class="hljs-selector-class">.flex-grow</span> { <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">1</span>}<span class="hljs-selector-class">.flex-shrink-0</span> { <span class="hljs-attribute">flex-shrink</span>: <span class="hljs-number">0</span>}<span class="hljs-selector-class">.flex-shrink</span> { <span class="hljs-attribute">flex-shrink</span>: <span class="hljs-number">1</span>}</code></pre><h2 id="01-Initial"><a href="#01-Initial" class="headerlink" title="01 - Initial"></a>01 - Initial</h2><ul><li>使用.flex-initial允许flex项收缩但不增长,同时考虑其初始大小:<img src="https://mmbiz.qpic.cn/mmbiz_png/9CWbA1ycFXdLQmScW47onTnaQAqFJMjLe9v8bN45syTl4Hgp2JfDtS1txX9OWyvvraLXpzZnibvb6Xr4ZpGKBZw/640?wx_fmt=png" srcset="/img/loading.gif" alt="">示例代码:</li></ul><pre><code class="hljs cs"><div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex bg-gray-200"</span>> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Short </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Medium length </div></div><div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex bg-gray-200"</span>> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Short </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Medium length </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui ad labore ipsam, aut rem quo repellat esse tempore id, quidem </div></div></code></pre><h2 id="02-flex-1"><a href="#02-flex-1" class="headerlink" title="02 - flex-1"></a>02 - flex-1</h2><p>使用.flex-1允许flex项根据需要增长和收缩,忽略其初始大小:<img src="https://mmbiz.qpic.cn/mmbiz_png/9CWbA1ycFXdLQmScW47onTnaQAqFJMjL8aWKRSr9twusx1qQOR0DqbPaMCryl4dSMflJCYnPga09nBh5fWg2zQ/640?wx_fmt=png" srcset="/img/loading.gif" alt="">示例代码: </p><pre><code class="hljs cs"><div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex bg-gray-200"</span>> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-1 text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Short </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-1 text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Medium length </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-1 text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Significantly larger amount of content </div></div></code></pre><h2 id="03-flex-auto"><a href="#03-flex-auto" class="headerlink" title="03 - flex-auto"></a>03 - flex-auto</h2><p>使用.flex-auto允许flex项增长和收缩,同时考虑其初始大小:<img src="https://mmbiz.qpic.cn/mmbiz_png/9CWbA1ycFXdLQmScW47onTnaQAqFJMjLBwokoelXa0aKcvh9icJxAeKFZ7wUUETxlESvIXOc4VXBWOfhTmMNk5A/640?wx_fmt=png" srcset="/img/loading.gif" alt="">示例代码:</p><pre><code class="hljs cs"><div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex bg-gray-200"</span>> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-auto text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Short </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-auto text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Medium length </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-auto text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Significantly larger amount of content </div></div></code></pre><h2 id="04-flex-none"><a href="#04-flex-none" class="headerlink" title="04 - flex-none"></a>04 - flex-none</h2><p>使用.flex-none可防止弹性项增长或收缩:<br><img src="https://mmbiz.qpic.cn/mmbiz_png/9CWbA1ycFXdLQmScW47onTnaQAqFJMjLVcPk0QDCx5jxO0K00XIQhIMibg818DibBOflmHp8BNEBzd3PY94jN2pw/640?wx_fmt=png" srcset="/img/loading.gif" alt="">示例代码: </p><pre><code class="hljs cs"><div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex bg-gray-200"</span>> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-1 text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Item that can grow or shrink <span class="hljs-keyword">if</span> needed </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-none text-gray-800 text-center bg-gray-500 px-4 py-2 m-2"</span>> Item that cannot grow or shrink </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-1 text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Item that can grow or shrink <span class="hljs-keyword">if</span> needed </div></div></code></pre><h2 id="5-flex-grow"><a href="#5-flex-grow" class="headerlink" title="5 - flex-grow"></a>5 - flex-grow</h2><ul><li>使用.flex-grow允许flex项增长以填充任何可用空间:<br><img src="https://mmbiz.qpic.cn/mmbiz_png/9CWbA1ycFXdLQmScW47onTnaQAqFJMjLvRqjnVlyUECuIMiamGlpTN1UMP4pv0IulMqebXQib6qms9HjbX2lTupw/640?wx_fmt=png" srcset="/img/loading.gif" alt="">示例代码:</li></ul><pre><code class="hljs cs"><div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex bg-gray-200"</span>> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-none text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Content that cannot flex </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-grow text-gray-800 text-center bg-gray-500 px-4 py-2 m-2"</span>> Item that will grow </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-none text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Content that cannot flex </div></div></code></pre><h2 id="06-flex-grow-0"><a href="#06-flex-grow-0" class="headerlink" title="06 - flex-grow-0"></a>06 - flex-grow-0</h2><ul><li>使用.flex-grow-0防止flex项增长:<img src="https://mmbiz.qpic.cn/mmbiz_png/9CWbA1ycFXdLQmScW47onTnaQAqFJMjL5zFpxhn0Vx6iajuMGzdHrGGMxxS5Z3icHOXzEV2gt9gNkx3a2Kom08Lg/640?wx_fmt=png" srcset="/img/loading.gif" alt="">代码示例:</li></ul><pre><code class="hljs cs"><div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex bg-gray-200"</span>> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-grow text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Will grow </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-grow-0 text-gray-800 text-center bg-gray-500 px-4 py-2 m-2"</span>> Will not grow </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-grow text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Will grow </div></div></code></pre><h2 id="07-flex-shrink"><a href="#07-flex-shrink" class="headerlink" title="07 - flex-shrink"></a>07 - flex-shrink</h2><ul><li>如果需要,使用.flex-shrink允许flex项收缩:<img src="https://mmbiz.qpic.cn/mmbiz_png/9CWbA1ycFXdLQmScW47onTnaQAqFJMjLibbY9afJHMaxS2knnTdibic6oFJIO9oMXGTdO9GAXVibVAOrI7InicjevZw/640?wx_fmt=png" srcset="/img/loading.gif" alt="">示例代码: </li></ul><pre><code class="hljs cs"><div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex bg-gray-200"</span>> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-none text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Longer content that cannot flex </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-shrink text-gray-800 text-center bg-gray-500 px-4 py-2 m-2"</span>> Item that will shrink even <span class="hljs-keyword">if</span> it causes the content to wrap </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-none text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Longer content that cannot flex </div></div></code></pre><h2 id="08-flex-shrink-0"><a href="#08-flex-shrink-0" class="headerlink" title="08 - flex-shrink-0"></a>08 - flex-shrink-0</h2><p>使用.flex-shrink-0来防止flex项收缩:<img src="https://mmbiz.qpic.cn/mmbiz_png/9CWbA1ycFXdLQmScW47onTnaQAqFJMjLZ8ia9eX6nNaiaSvYWMKL0C3AVSmea4WYc2zvrs9CTfjWGYCbJ0xXgGUg/640?wx_fmt=png" srcset="/img/loading.gif" alt="">示例代码:</p><pre><code class="hljs cs"><div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex bg-gray-200"</span>> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-shrink text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Item that can shrink <span class="hljs-keyword">if</span> needed </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-shrink-0 text-gray-800 text-center bg-gray-500 px-4 py-2 m-2"</span>> Item that cannot shrink below its initial size </div> <div <span class="hljs-keyword">class</span>=<span class="hljs-string">"flex-shrink text-gray-700 text-center bg-gray-400 px-4 py-2 m-2"</span>> Item that can shrink <span class="hljs-keyword">if</span> needed </div></div></code></pre><p><img src="https://mmbiz.qpic.cn/mmbiz_png/IBnQicdia1GV6KnlBZps4t7Jkib94H4cVRQZZZPmvrunrENrQugdyEFkxuibnlThicwxcqNoHKm09FKjen5FLOfa6vA/640" srcset="/img/loading.gif" alt=""></p><h1 id="扫描二维码获取更多精彩-或者微信公众号搜索:极客兵营"><a href="#扫描二维码获取更多精彩-或者微信公众号搜索:极客兵营" class="headerlink" title="扫描二维码获取更多精彩,或者微信公众号搜索:极客兵营"></a>扫描二维码获取更多精彩,或者微信公众号搜索:极客兵营</h1><p><img src="https://mmbiz.qpic.cn/mmbiz_jpg/9CWbA1ycFXcWpaIW71xMhFEBFMkgmSsBgZBq28OibnPhFdKUcODee5gsBDEAGLQZN6icP2SO0SDMVMdfNic95tyLA/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""></p>]]></content>
<categories>
<category>tailwindcss</category>
</categories>
<tags>
<tag>tailwindcss</tag>
</tags>
</entry>
<entry>
<title>程序员的噩梦,你遇到过哪几条?</title>
<link href="/2020-05-31/ckaxfq6vv000110qs7826h384.html"/>
<url>/2020-05-31/ckaxfq6vv000110qs7826h384.html</url>
<content type="html"><![CDATA[<p><img src="https://mpt.135editor.com/mmbiz_gif/6aVaON9Kibf5ibKRPQgZ9XgbVNsIeQUnfKy4ia9OoKXgFWC78shRtzFR8icyLGazjnMGfyME6zwiadltkTakg8V0icag/640?" srcset="/img/loading.gif" alt=""></p><blockquote><p>如果你交给某人一个程序,你将折磨他一整天;如果你教某人如何编写程序,你将折磨他一辈子。——David Leinweber</p></blockquote><h2 id="1、网上找不到答案"><a href="#1、网上找不到答案" class="headerlink" title="1、网上找不到答案"></a>1、网上找不到答案</h2><p><img src="https://mpt.135editor.com/mmbiz/vqlbVFl5Jn1q3hZvtWXRaX2zjBeZYaO2oOtC7P9rkALgyiaNlW59BfLOiacsEkPzt3DNnnMnrnmABtwHvDpGF39Q/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt="">)<img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn1cHp76RLwUGOQ99icxs7CCNquWMwwMT8xvqrwVnIDFbSZvbOm7z3x0hgGN599hLlw9D0OuV2M8UxA/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""> </p><h2 id="2、最重要的键盘键坏了"><a href="#2、最重要的键盘键坏了" class="headerlink" title="2、最重要的键盘键坏了)"></a>2、最重要的键盘键坏了<img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn1cHp76RLwUGOQ99icxs7CCNiaesfFdH3EtCH0PNpA3WEhfEGYkEqRJSIGvFqM6PiaVAB0DsPuwALadg/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt="">)<img src="https://mpt.135editor.com/mmbiz/vqlbVFl5Jn1q3hZvtWXRaX2zjBeZYaO21YkhOICGzbVKsQfvG8JhCh5UfKpic75qQkIL3SVpqZplQMLZKNc9ouw/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""></h2><h2 id="3、网崩了"><a href="#3、网崩了" class="headerlink" title="3、网崩了 "></a>3、网崩了 <img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn1cHp76RLwUGOQ99icxs7CCN5wCTfvjbmibQEHmFcoZ53t8puBiafjqMFggmROxvCQ3dZEntD3R68s7w/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""></h2><h2 id="4、Bug-无法重现"><a href="#4、Bug-无法重现" class="headerlink" title="4、Bug 无法重现"></a>4、Bug 无法重现<img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn1cHp76RLwUGOQ99icxs7CCNszfvSNkOgBvK8MuCo3kyV0pw3SlISxXmBtItibUfhbroRXjdv0kmiamg/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""></h2><h2 id="5、我的-bug-伤害了别人"><a href="#5、我的-bug-伤害了别人" class="headerlink" title="5、我的 bug 伤害了别人"></a>5、我的 bug 伤害了别人</h2><p><img src="https://mpt.135editor.com/mmbiz_gif/vqlbVFl5Jn0yia0lb9uo55motschtQnpdxtqbWLHpTjLLjk3a8iadmuzX5dOjKsHFWP9THT1roIKnw1jMf9ibAZ8w/640?wx_fmt=gif" srcset="/img/loading.gif" alt=""> </p><h2 id="6、没有文档或注释"><a href="#6、没有文档或注释" class="headerlink" title="6、没有文档或注释"></a>6、没有文档或注释</h2><p><img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn1cHp76RLwUGOQ99icxs7CCNQRhbkrhibX9YWn3oMHTe2Jia7GJG85khIynWLqqw6nK4O6azNHgjrkMA/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""> </p><h2 id="7、生病,不能写任何代码了"><a href="#7、生病,不能写任何代码了" class="headerlink" title="7、生病,不能写任何代码了"></a>7、生病,不能写任何代码了<img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn0yia0lb9uo55motschtQnpdWQ7ImD3dExw22WOCK4I8HmqzQddAS5jkDLs7FN8tqlDUh5icj1jZCNA/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""></h2><h2 id="8、遇到糟糕的老板或主管"><a href="#8、遇到糟糕的老板或主管" class="headerlink" title="8、遇到糟糕的老板或主管"></a>8、遇到糟糕的老板或主管</h2><p><img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn0yia0lb9uo55motschtQnpdD2FKicHicxxViab7La02BbdxHcicf08KhTqkXia27F0ws2T2BqbwhAjR9Xg/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""> </p><h2 id="9、清理其他人的代码"><a href="#9、清理其他人的代码" class="headerlink" title="9、清理其他人的代码"></a>9、清理其他人的代码</h2><p><img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn0jXHVHGyzNH5hJtg1QicklvmcAvQ2BkGN4ca9DAWJLpcEEBTKibgiblp9Lg7tlSqkmHKaHsglUwEa8g/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt="">)<img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn2ohLMYkficIbP8E9s6C5zJSfFLC1jYQYB484HDae0p0xfFIicO6y00xILSNZNbnZ77oyHZ7wWXB2icg/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""> </p><h2 id="10、需求变更"><a href="#10、需求变更" class="headerlink" title="10、需求变更"></a>10、需求变更</h2><p><img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn2ohLMYkficIbP8E9s6C5zJSLRKnl08SlqxK4x8hy1sRRuwzE9R2zk5rvaCHfwuvgqY1XqyCZq61bw/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""> </p><h2 id="11、代码丢失了!"><a href="#11、代码丢失了!" class="headerlink" title="11、代码丢失了!"></a>11、代码丢失了!</h2><p><img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn2ohLMYkficIbP8E9s6C5zJS42NuYma4DZIicG51spB4GuvrSibCOkRW3KeD8wg5LOB4QO4jB0B8E1hQ/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""> </p><h2 id="12、令人头痛的IE浏览器"><a href="#12、令人头痛的IE浏览器" class="headerlink" title="12、令人头痛的IE浏览器"></a>12、令人头痛的IE浏览器</h2><p><img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn2ohLMYkficIbP8E9s6C5zJSMjOHUjuW5X5NIFkd6djMQ2KpChQN2ic0WQQDhsRxtqZQEg6934fUJaQ/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""></p><h2 id="13、段错误(segmentation-fault)"><a href="#13、段错误(segmentation-fault)" class="headerlink" title="13、段错误(segmentation fault)"></a>13、段错误(segmentation fault)</h2><p><img src="https://mpt.135editor.com/mmbiz_jpg/vqlbVFl5Jn0yia0lb9uo55motschtQnpdIdwFUStDUzCwYWnymMmZUxhO3dnibBeYDJhSvX0lmiaM5k4dR4dpTaSA/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt="">**</p><p><img src="https://mpt.135editor.com/mmbiz_jpg/9CWbA1ycFXcFE9hPe4GDr2JOmg5qqkzFRiaib79ghianfCcyeYDh9WAUE5bjSFX2jVDgcQnDC2dibJxRIU9QH1iaBgg/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""></p><p><img src="https://mpt.135editor.com/mmbiz_png/IBnQicdia1GV6KnlBZps4t7Jkib94H4cVRQZZZPmvrunrENrQugdyEFkxuibnlThicwxcqNoHKm09FKjen5FLOfa6vA/640" srcset="/img/loading.gif" alt=""></p><h1 id="扫描二维码获取更多精彩!!!"><a href="#扫描二维码获取更多精彩!!!" class="headerlink" title="扫描二维码获取更多精彩!!!"></a>扫描二维码获取更多精彩!!!</h1><p><img src="https://mpt.135editor.com/mmbiz_jpg/9CWbA1ycFXcWpaIW71xMhFEBFMkgmSsBgZBq28OibnPhFdKUcODee5gsBDEAGLQZN6icP2SO0SDMVMdfNic95tyLA/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""></p>]]></content>
<categories>
<category>others</category>
</categories>
<tags>
<tag>others</tag>
<tag>note</tag>
</tags>
</entry>
<entry>
<title>Docker菜鸟初级篇---安装</title>
<link href="/2020-05-31/ckaxfq6wa000d10qsh6jf7ubx.html"/>
<url>/2020-05-31/ckaxfq6wa000d10qsh6jf7ubx.html</url>
<content type="html"><![CDATA[<p><img src="https://mpt.135editor.com/mmbiz_gif/6aVaON9Kibf5ibKRPQgZ9XgbVNsIeQUnfKy4ia9OoKXgFWC78shRtzFR8icyLGazjnMGfyME6zwiadltkTakg8V0icag/640?" srcset="/img/loading.gif" alt=""></p><p>任何一个工具,它的一个最重要的、同时也是最难以做到的方面就是对那些学习使用这个工具的人在使用习惯上的影响。如果这个工具是一种编程语言,那么,这种影响——不管我们是否喜欢——将是一种思考习惯上的影响。</p><p><img src="https://mpt.135editor.com/mmbiz_gif/yIGVCsrQyYJHvJUMS22qwaDJM2sbtdjc8SdOkeT47kLx1b7j1Xsco5KgiarichObx7dCgiaLdjDjcPvYdoFKob6WQ/640" srcset="/img/loading.gif" alt=""></p><p>正文共:4875字 11图预计阅读时间:13分钟</p><pre><code>Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。 Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。 容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。 Docker 从 17.03 版本之后分为 CE(Community Edition: 社区版) 和 EE(Enterprise Edition: 企业版),我们用社区版就可以了。 </code></pre><p><strong>1</strong></p><p>Docker 安装</p><p>1</p><p>使用官方安装脚本自动安装 (仅适用于公网环境) </p><p>系统环境为:Centos 7.7 64位,至于为什么不用centos8,是因为新版本系统方面的兼容还没有那么完善,做为服务而言必须使用稳定一点的系统。 </p><pre><code class="hljs nginx"><span class="hljs-attribute">curl</span> -fsSL https://get.docker.com | bash -s docker --mirror Aliyun</code></pre><p><img src="https://mpt.135editor.com/mmbiz_png/9CWbA1ycFXfDT2U365wpgU68vO6ZpiaTvxOREoAhnCCUmAicbYSFJ6s8N1lDPUD3Ibt5CS3azud03dCHaURlYicrg/640?wx_fmt=png" srcset="/img/loading.gif" alt="">)<img src="https://mpt.135editor.com/mmbiz_png/9CWbA1ycFXfDT2U365wpgU68vO6ZpiaTvAIWrl7LeomgNNEWg89Hbhz7bKC0aQzvuicQKyOqhRf4gAx4wQjFRZrg/640?wx_fmt=png" srcset="/img/loading.gif" alt="">)<img src="https://mpt.135editor.com/mmbiz_png/9CWbA1ycFXfDT2U365wpgU68vO6ZpiaTvwS0GqUnjUeJ0O4uGPWNpQ14jQGNd3W7iaQAEx0zuriaDDcKdMlHGyXQA/640?wx_fmt=png" srcset="/img/loading.gif" alt=""><br>提示安装成功,但是会提醒你使用非Root管理员去运行docker </p><p>02</p><p>手动安装帮助 (阿里云ECS可以通过内网安装,见注释部分内容)</p><h2 id="01-Ubuntu-14-04-16-04-使用apt-get进行安装"><a href="#01-Ubuntu-14-04-16-04-使用apt-get进行安装" class="headerlink" title="01 - Ubuntu 14.04 16.04 (使用apt-get进行安装)"></a>01 - Ubuntu 14.04 16.04 (使用apt-get进行安装)</h2><pre><code class="hljs sql"><span class="hljs-comment"># step 1: 安装必要的一些系统工具</span>sudo apt-get <span class="hljs-keyword">update</span>sudo apt-<span class="hljs-keyword">get</span> -y <span class="hljs-keyword">install</span> apt-transport-https ca-certificates curl software-properties-common<span class="hljs-comment"># step 2: 安装GPG证书</span>curl -fsSL <span class="hljs-keyword">http</span>://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-<span class="hljs-keyword">key</span> <span class="hljs-keyword">add</span> -<span class="hljs-comment"># Step 3: 写入软件源信息</span>sudo <span class="hljs-keyword">add</span>-apt-repository <span class="hljs-string">"deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"</span><span class="hljs-comment"># Step 4: 更新并安装 Docker-CE</span>sudo apt-<span class="hljs-keyword">get</span> -y <span class="hljs-keyword">update</span>sudo apt-<span class="hljs-keyword">get</span> -y <span class="hljs-keyword">install</span> docker-ce注意:其他注意事项在下面的注释中<span class="hljs-comment"># 安装指定版本的Docker-CE:</span><span class="hljs-comment"># Step 1: 查找Docker-CE的版本:</span><span class="hljs-comment"># apt-cache madison docker-ce</span><span class="hljs-comment"># docker-ce | 17.03.1~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages</span><span class="hljs-comment"># docker-ce | 17.03.0~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages</span><span class="hljs-comment"># Step 2: 安装指定版本的Docker-CE: (VERSION 例如上面的 17.03.1~ce-0~ubuntu-xenial)</span><span class="hljs-comment"># sudo apt-get -y install docker-ce=[VERSION]</span><span class="hljs-comment"># 通过经典网络、VPC网络内网安装时,用以下命令替换Step 2、Step 3中的命令</span><span class="hljs-comment"># 经典网络:</span><span class="hljs-comment"># curl -fsSL http://mirrors.aliyuncs.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -</span><span class="hljs-comment"># sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyuncs.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"</span><span class="hljs-comment"># VPC网络:</span><span class="hljs-comment"># curl -fsSL http://mirrors.cloud.aliyuncs.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -</span><span class="hljs-comment"># sudo add-apt-repository "deb [arch=amd64] http://mirrors.cloud.aliyuncs.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"</span></code></pre><h2 id="02-CentOS-7-使用yum进行安装"><a href="#02-CentOS-7-使用yum进行安装" class="headerlink" title="02 - CentOS 7 (使用yum进行安装)"></a>02 - CentOS 7 (使用yum进行安装)</h2><pre><code class="hljs sql"><span class="hljs-comment"># step 1: 安装必要的一些系统工具</span>sudo yum <span class="hljs-keyword">install</span> -y yum-utils device-mapper-persistent-<span class="hljs-keyword">data</span> lvm2<span class="hljs-comment"># Step 2: 添加软件源信息</span>sudo yum-config-manager <span class="hljs-comment">--add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</span><span class="hljs-comment"># Step 3: 更新并安装 Docker-CE</span>sudo yum makecache <span class="hljs-keyword">fast</span>sudo yum -y <span class="hljs-keyword">install</span> docker-ce<span class="hljs-comment"># Step 4: 开启Docker服务</span>sudo service docker <span class="hljs-keyword">start</span>注意:其他注意事项在下面的注释中<span class="hljs-comment"># 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,你可以通过以下方式开启。同理可以开启各种测试版本等。</span><span class="hljs-comment"># vim /etc/yum.repos.d/docker-ce.repo</span><span class="hljs-comment"># 将 [docker-ce-test] 下方的 enabled=0 修改为 enabled=1</span><span class="hljs-comment">#</span><span class="hljs-comment"># 安装指定版本的Docker-CE:</span><span class="hljs-comment"># Step 1: 查找Docker-CE的版本:</span><span class="hljs-comment"># yum list docker-ce.x86_64 --showduplicates | sort -r</span><span class="hljs-comment"># Loading mirror speeds from cached hostfile</span><span class="hljs-comment"># Loaded plugins: branch, fastestmirror, langpacks</span><span class="hljs-comment"># docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable</span><span class="hljs-comment"># docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable</span><span class="hljs-comment"># docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable</span><span class="hljs-comment"># Available Packages</span><span class="hljs-comment"># Step2 : 安装指定版本的Docker-CE: (VERSION 例如上面的 17.03.0.ce.1-1.el7.centos)</span><span class="hljs-comment"># sudo yum -y install docker-ce-[VERSION]</span><span class="hljs-comment"># 注意:在某些版本之后,docker-ce安装出现了其他依赖包,如果安装失败的话请关注错误信息。例如 docker-ce 17.03 之后,需要先安装 docker-ce-selinux。</span><span class="hljs-comment"># yum list docker-ce-selinux- --showduplicates | sort -r</span><span class="hljs-comment"># sudo yum -y install docker-ce-selinux-[VERSION]</span><span class="hljs-comment"># 通过经典网络、VPC网络内网安装时,用以下命令替换Step 2中的命令</span><span class="hljs-comment"># 经典网络:</span><span class="hljs-comment"># sudo yum-config-manager --add-repo http://mirrors.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo</span><span class="hljs-comment"># VPC网络:</span><span class="hljs-comment"># sudo yum-config-manager --add-repo http://mirrors.could.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo</span></code></pre><h2 id="安装校验"><a href="#安装校验" class="headerlink" title="安装校验"></a>安装校验</h2><pre><code class="hljs nginx"><span class="hljs-attribute">docker</span> version<span class="hljs-comment"># 如果只想输出docker版本信息</span>docker -v <span class="hljs-comment"># 或者用 docker --version</span></code></pre><p><img src="https://mpt.135editor.com/mmbiz_png/9CWbA1ycFXfDT2U365wpgU68vO6ZpiaTvIPMWE1YJQXNA2PUCHUEC39tSM2SNtc981TmWmHfTra8nBttAGIlP5g/640?wx_fmt=png" srcset="/img/loading.gif" alt="">这个提示是还没有启动docker后台进程 </p><pre><code class="hljs properties"><span class="hljs-attr">sudo</span> <span class="hljs-string">systemctl daemon-reload</span><span class="hljs-attr">sudo</span> <span class="hljs-string">systemctl restart docker</span></code></pre><p>重新运行如下:<img src="https://mpt.135editor.com/mmbiz_png/9CWbA1ycFXfDT2U365wpgU68vO6ZpiaTvu4UegujPhJD5n8OvYVAbMn4eAztsiaK13WxO3wWZAChkAjcBia36J3QQ/640?wx_fmt=png" srcset="/img/loading.gif" alt=""> </p><p><strong>2</strong></p><p>Docker 加速器</p><p>针对Docker客户端版本大于 1.10.0 的用户您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器,下面这个是我自己阿里云的加速器地址,可以替换为自己的。<img src="https://mpt.135editor.com/mmbiz_png/9CWbA1ycFXfDT2U365wpgU68vO6ZpiaTvbO3OGZbpYhichSZhRysjyBPcYQIHm71rAOM9gqOFCuaNEyA9ueg6JcQ/640?wx_fmt=png" srcset="/img/loading.gif" alt=""></p><pre><code class="hljs perl">sudo <span class="hljs-keyword">mkdir</span> -p /etc/dockersudo tee /etc/docker/daemon.json <<-<span class="hljs-string">'EOF'</span>{ <span class="hljs-string">"registry-mirrors"</span>: [<span class="hljs-string">"https://g0p1kah0.mirror.aliyuncs.com"</span>]}EOFsudo systemctl daemon-reloadsudo systemctl restart docker</code></pre><p>3 </p><p>Docker-Compose </p><pre><code>Docker Compose是 docker 提供的一个命令行工具,用来定义和运行由多个容器组成的应用。使用 compose,我们可以通过 YAML 文件声明式的定义应用程序的各个服务,并由单个命令完成应用的创建和启动。 Docker Compose 存放在Git Hub,不太稳定。 你可以也通过执行下面的命令,高速安装Docker Compose。</code></pre><pre><code class="hljs ruby">curl -L <span class="hljs-symbol">https:</span>/<span class="hljs-regexp">/get.daocloud.io/docker</span><span class="hljs-regexp">/compose/releases</span><span class="hljs-regexp">/download/</span><span class="hljs-number">1.25</span>.<span class="hljs-number">4</span>/docker-compose-<span class="hljs-string">`uname -s`</span>-<span class="hljs-string">`uname -m`</span> > <span class="hljs-regexp">/usr/local</span><span class="hljs-regexp">/bin/docker</span>-composechmod +x /usr/local/bin/docker-compose</code></pre><p>你可以通过修改URL中的版本,可以自定义您的需要的版本。 </p><p><strong>4</strong></p><p>卸载 Docker</p><p> Ubuntu|Debian</p><pre><code class="hljs cs">sudo apt-<span class="hljs-keyword">get</span> <span class="hljs-keyword">remove</span> docker docker-engine</code></pre><p>RHEL|CentOS</p><pre><code class="hljs properties"><span class="hljs-attr">sudo</span> <span class="hljs-string">yum remove docker \</span><span class="hljs-meta">docker-common</span> <span class="hljs-string">\</span><span class="hljs-meta">container-selinux</span> <span class="hljs-string">\</span><span class="hljs-meta">docker-selinux</span> <span class="hljs-string">\</span><span class="hljs-attr">docker-engine</span></code></pre><p>Fedora</p><pre><code class="hljs properties"><span class="hljs-attr">sudo</span> <span class="hljs-string">dnf remove docker \</span><span class="hljs-meta">docker-common</span> <span class="hljs-string">\</span><span class="hljs-meta">container-selinux</span> <span class="hljs-string">\</span><span class="hljs-meta">docker-selinux</span> <span class="hljs-string">\</span><span class="hljs-attr">docker-engine</span></code></pre><p>卸载Docker后,/var/lib/docker/目录下会保留原Docker的镜像,网络,存储卷等文件. 如果需要全新安装Docker,需要删除/var/lib/docker/目录</p><pre><code class="hljs javascript">rm -fr /<span class="hljs-keyword">var</span>/lib/docker/</code></pre><p><img src="https://mpt.135editor.com/mmbiz_png/IBnQicdia1GV6KnlBZps4t7Jkib94H4cVRQZZZPmvrunrENrQugdyEFkxuibnlThicwxcqNoHKm09FKjen5FLOfa6vA/640" srcset="/img/loading.gif" alt=""></p><p><img src="https://mpt.135editor.com/mmbiz_jpg/9CWbA1ycFXcWpaIW71xMhFEBFMkgmSsBgZBq28OibnPhFdKUcODee5gsBDEAGLQZN6icP2SO0SDMVMdfNic95tyLA/640?wx_fmt=jpeg" srcset="/img/loading.gif" alt=""></p>]]></content>
<categories>
<category>docker</category>
</categories>
<tags>
<tag>docker</tag>
<tag>docker教程</tag>
<tag>原创</tag>
<tag>docker安装</tag>
</tags>
</entry>
<entry>
<title>Docker傻瓜教程--镜像篇!看了这篇教程还学不会!那我也没办法了!</title>
<link href="/2020-05-31/ckaxfq6wl000o10qsayp640fe.html"/>
<url>/2020-05-31/ckaxfq6wl000o10qsayp640fe.html</url>
<content type="html"><![CDATA[<h1 id="Docker的体系架构"><a href="#Docker的体系架构" class="headerlink" title="Docker的体系架构"></a>Docker的体系架构</h1><p><img src="https://imgkr.cn-bj.ufileos.com/2eae1ea0-e4ea-41c4-9e43-8bd94d4aaa6e.png" srcset="/img/loading.gif" alt=""><br>Containerd:是一个简单的守护进程,使用runC管理容器。向Docker Engine提<br>供接口。<br>Shim:只负责管理一个容器。<br>runC:是一个轻量级的工具,只用来运行容器。<br><img src="https://imgkr.cn-bj.ufileos.com/041fe10d-eb90-4150-8882-cb6cb2f6123f.png" srcset="/img/loading.gif" alt=""></p><hr><h1 id="docker的内部组件"><a href="#docker的内部组件" class="headerlink" title="docker的内部组件"></a>docker的内部组件</h1><ol><li><p>Namespaces<br>命名空间,Linux内核提供的一种对进程资源隔离的机制,例如进程、网络、挂载点等资源。</p></li><li><p>CGroups<br>控制组,Linux内核提供的一种限制进程资源的机制;例如CPU、内存等资源。</p></li><li><p>UnionFS<br>联合文件系统,支持将不同位置的目录挂载到同一虚拟文件系统,形成一种分层的模型。</p><h1 id="Docker是CS架构,主要有两个概念:"><a href="#Docker是CS架构,主要有两个概念:" class="headerlink" title="Docker是CS架构,主要有两个概念:"></a>Docker是CS架构,主要有两个概念:</h1><ul><li><p>Docker daemon: 运行在宿主机上,Docker守护进程,用户通过Docker client(Docker命令)与Docker daemon交互 </p></li><li><p>Docker client: Docker 命令行工具,是用户使用Docker的主要方式,Docker client与Docker daemon通信并将结果返回给用户,Docker client也可以通过socket或者RESTful api访问远程的Docker daemon。 </p></li></ul></li></ol><p><img src="https://imgkr.cn-bj.ufileos.com/f40fb83e-0eb4-4ede-9aac-6b207b574200.png" srcset="/img/loading.gif" alt=""></p><a id="more"></a><pre><code class="hljs plain">优秀的判断力来自经验,但经验来自于错误的判断。Good judgment comes from experience, and experience comes from bad judgment.</code></pre><h2 id="正文共:8282字-15图"><a href="#正文共:8282字-15图" class="headerlink" title="正文共:8282字 15图"></a>正文共:8282字 15图</h2><h2 id="预计阅读时间:21分钟"><a href="#预计阅读时间:21分钟" class="headerlink" title="预计阅读时间:21分钟"></a>预计阅读时间:21分钟</h2><h1 id="Docker的体系架构-1"><a href="#Docker的体系架构-1" class="headerlink" title="Docker的体系架构"></a>Docker的体系架构</h1><p><img src="https://imgkr.cn-bj.ufileos.com/2eae1ea0-e4ea-41c4-9e43-8bd94d4aaa6e.png" srcset="/img/loading.gif" alt=""><br>Containerd:是一个简单的守护进程,使用runC管理容器。向Docker Engine提<br>供接口。<br>Shim:只负责管理一个容器。<br>runC:是一个轻量级的工具,只用来运行容器。<br><img src="https://imgkr.cn-bj.ufileos.com/041fe10d-eb90-4150-8882-cb6cb2f6123f.png" srcset="/img/loading.gif" alt=""></p><hr><h1 id="docker的内部组件-1"><a href="#docker的内部组件-1" class="headerlink" title="docker的内部组件"></a>docker的内部组件</h1><ol><li><p>Namespaces<br>命名空间,Linux内核提供的一种对进程资源隔离的机制,例如进程、网络、挂载点等资源。</p></li><li><p>CGroups<br>控制组,Linux内核提供的一种限制进程资源的机制;例如CPU、内存等资源。</p></li><li><p>UnionFS<br>联合文件系统,支持将不同位置的目录挂载到同一虚拟文件系统,形成一种分层的模型。</p><h1 id="Docker是CS架构,主要有两个概念:-1"><a href="#Docker是CS架构,主要有两个概念:-1" class="headerlink" title="Docker是CS架构,主要有两个概念:"></a>Docker是CS架构,主要有两个概念:</h1><ul><li><p>Docker daemon: 运行在宿主机上,Docker守护进程,用户通过Docker client(Docker命令)与Docker daemon交互 </p></li><li><p>Docker client: Docker 命令行工具,是用户使用Docker的主要方式,Docker client与Docker daemon通信并将结果返回给用户,Docker client也可以通过socket或者RESTful api访问远程的Docker daemon。 </p></li></ul></li></ol><p><img src="https://imgkr.cn-bj.ufileos.com/f40fb83e-0eb4-4ede-9aac-6b207b574200.png" srcset="/img/loading.gif" alt=""></p><h1 id="Docker的三大概念"><a href="#Docker的三大概念" class="headerlink" title="Docker的三大概念"></a>Docker的三大概念</h1><h2 id="了解了Docker的组成,再来了解一下Docker的三个主要概念:"><a href="#了解了Docker的组成,再来了解一下Docker的三个主要概念:" class="headerlink" title="了解了Docker的组成,再来了解一下Docker的三个主要概念:"></a>了解了Docker的组成,再来了解一下Docker的三个主要概念:</h2><ul><li><p>Docker image:镜像是只读的,镜像中包含有需要运行的文件。镜像用来创建container,一个镜像可以运行多个container;镜像可以通过Dockerfile创建,也可以从Docker hub/registry上下载。</p></li><li><p>Docker container:容器是Docker的运行组件,启动一个镜像就是一个容器,容器是一个隔离环境,多个容器之间不会相互影响,保证容器中的程序运行在一个相对安全的环境中。</p></li><li><p>Docker hub/registry: 共享和管理Docker镜像,用户可以上传或者下载上面的镜像,官方地址为 <a href="https://registry.hub.docker.com/,也可以搭建自己私有的Docker" target="_blank" rel="noopener">https://registry.hub.docker.com/,也可以搭建自己私有的Docker</a> registry。</p></li></ul><p>镜像就相当于打包好的版本,镜像启动之后运行在容器中,仓库就是装存储镜像的地方。<br>| | |<br>| :—-: | :—-: |<br>| 镜像 | image |<br>| 容器 | container |<br>| 仓库 | repository |</p><h1 id="Docker-基本命令行"><a href="#Docker-基本命令行" class="headerlink" title="Docker 基本命令行"></a>Docker 基本命令行</h1><pre><code class="hljs plain">docker --help(中文注解)Usage: docker [OPTIONS] COMMANDA self-sufficient runtime for containersOptions: --config string Location of client config files (default "/root/.docker") -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quitManagement Commands: builder Manage builds config Manage Docker configs container Manage containers context Manage contexts engine Manage the docker engine image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker trust Manage trust on Docker images volume Manage volumesCommands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command. #运行docker命令在帮助可以获取更多信息# 常用命令docker search hello-world # 搜索hello-docker的镜像docker search centos # 搜索centos镜像docker pull hello-world # 获取centos镜像docker run hello-world #运行一个docker镜像,产生一个容器实例(也可以通过镜像id前三位运行)docker image ls # 查看本地所有镜像docker images # 查看docker镜像docker image rmi hello-world # 删除centos镜像docker ps #列出正在运行的容器(如果创建容器中没有进程正在运行,容器就会立即停止)docker ps -a # 列出所有运行过的容器记录docker save centos > /opt/centos.tar.gz # 导出docker镜像至本地docker load < /opt/centos.tar.gz #导入本地镜像到docker镜像库docker stop `docker ps -aq` # 停止所有正在运行的容器docker rm `docker ps -aq` # 一次性删除所有容器记录docker rmi `docker images -aq` # 一次性删除所有本地的镜像记录</code></pre><pre><code class="hljs plain">docker <选项><命令><参数></code></pre><p><img src="https://imgkr.cn-bj.ufileos.com/c4665254-41d6-4945-9894-4de970cade5e.png" srcset="/img/loading.gif" alt=""></p><p><img src="https://imgkr.cn-bj.ufileos.com/c72c8691-97a1-40f0-af9a-010c706be917.png" srcset="/img/loading.gif" alt=""></p><h3 id="docker-现在以两种方法运行,一种是Management-Commands-一种是Commands"><a href="#docker-现在以两种方法运行,一种是Management-Commands-一种是Commands" class="headerlink" title="docker 现在以两种方法运行,一种是Management Commands: 一种是Commands:"></a>docker 现在以两种方法运行,一种是Management Commands: 一种是Commands:</h3><p>至于为什么会出现这两种方式,一开始是版本开始只有Commands,后面版本统一为</p><p>Management Commands,所以在下面的教程就可能出现两种运行方式都是一样的效果。<br>首先,我们介绍镜像。</p><h1 id="Docker-镜像"><a href="#Docker-镜像" class="headerlink" title="Docker 镜像"></a>Docker 镜像</h1><h2 id="什么是镜像"><a href="#什么是镜像" class="headerlink" title="什么是镜像"></a>什么是镜像</h2><ul><li><p>镜像是一个特殊的文件系统,除了提供容器运行时所需的程序、库、资源、<br>配置等文件外,还包含了一些为运行时准备的一些配置参数。镜像是容器在本地<br>运行的基础,Dokcer运行容器前需要本地存在对应的镜像,如果不存在对应的镜<br>像,Docker 会先从默认的镜像仓库下载(如果用户不希望Docker从默认的镜像<br>仓库下载镜像的话,可以使用自定义镜像仓库)。 </p></li><li><p>镜像(Image)就是一堆只读层(read-only layer)的统一视角,也许这个<br>定义有些难以理解,下面的这张图能够帮助读者理解镜像的定义。<br><img src="https://imgkr.cn-bj.ufileos.com/1e266544-449b-40e3-928d-6d1c33cac604.png" srcset="/img/loading.gif" alt=""></p></li><li><p>从左边我们看到了多个只读层,它们重叠在一起。除了最下面一层,其它层都会有一个指针指向下一层。这些层是Docker内部的实现细节,并且能够在主机(译者注:运行Docker的机器)的文件系统上访问到。统一文件系统(union file system)技术能够将不同的层整合成一个文件系统,为这些层提供了一个统一的视角,这样就隐藏了多层的存在,在用户的角度看来,只存在一个文件系统。我们可以在图片的右边看到这个视角的形式。</p><h1 id="镜像拉取"><a href="#镜像拉取" class="headerlink" title="镜像拉取"></a>镜像拉取</h1></li><li><p>Docker 主机安装之后,本地并没有镜像。 </p></li><li><p>docker image pull 是下载镜像的命令。镜像从远程镜像仓库服务的仓库中下载。 </p></li><li><p>默认情况下,镜像会从 Docker Hub 的仓库中拉取。docker image pull alpine:latest 命令会从 Docker Hub 的 alpine 仓库中拉取标签为 latest 的镜像。</p></li><li><p>Linux Docker 主机本地镜像仓库通常位于 /var/lib/docker/<storage-driver>,Windows Docker 主机则是 C:\ProgramData\docker\windowsfilter。</p><pre><code class="hljs plain">docker image pull alpine# 或者直接使用:docker pull alpine</code></pre><p><img src="https://imgkr.cn-bj.ufileos.com/4aaa49b3-c0c2-46f3-b158-8585095fdd6b.png" srcset="/img/loading.gif" alt=""></p><h1 id="镜像仓库服务"><a href="#镜像仓库服务" class="headerlink" title="镜像仓库服务"></a>镜像仓库服务</h1></li></ul><p>Docker 镜像存储在镜像仓库服务(Image Registry)当中。</p><p>Docker 客户端的镜像仓库服务是可配置的,默认使用 Docker Hub。</p><p>镜像仓库服务包含多个镜像仓库(Image Repository)。同样,一个镜像仓库中可以包含多个镜像。</p><p>可能这听起来让人有些迷惑,所以下图展示了包含 3 个镜像仓库的镜像仓库服务,其中每个镜像仓库都包含一个或多个镜像。<br><img src="https://imgkr.cn-bj.ufileos.com/0e9ec6d8-bda2-4d8f-aec4-e1c32b3ab7e8.png" srcset="/img/loading.gif" alt=""></p><p>官方和非官方镜像仓库<br>Docker Hub 也分为官方仓库(Official Repository)和非官方仓库(Unofficial Repository)。</p><p>顾名思义,官方仓库中的镜像是由 Docker 公司审查的。这意味着其中的镜像会及时更新,由高质量的代码构成,这些代码是安全的,有完善的文档和最佳实践。</p><p>非官方仓库更像江湖侠客,其中的镜像不一定具备官方仓库的优点,但这并不意味着所有非官方仓库都是不好的!非官方仓库中也有一些很优秀的镜像。</p><p>在信任非官方仓库镜像代码之前需要我们保持谨慎。说实话,读者在使用任何从互联网上下载的软件之前,都要小心,甚至是使用那些来自官方仓库的镜像时也应如此。</p><p>大部分流行的操作系统和应用在 Docker Hub 的官方仓库中都有其对应镜像。这些镜像很容易找到,基本都在 Docker Hub 命名空间的顶层。</p><h2 id="镜像命名和标签"><a href="#镜像命名和标签" class="headerlink" title="镜像命名和标签"></a>镜像命名和标签</h2><p>只需要给出镜像的名字和标签,就能在官方仓库中定位一个镜像(采用“:”分隔)。从官方仓库拉取镜像时,docker image pull 命令的格式如下。</p><pre><code class="hljs plain">docker image pull <repository>:<tag></code></pre><p>在之前的 Linux 示例中,通过下面的两条命令完成 Alpine 和 Ubuntu 镜像的拉取。</p><pre><code class="hljs plain">docker image pull alpine:latestdocker image pull ubuntu:latest</code></pre><p>这两条命令从 alpine 和 ubuntu 仓库拉取了标有“latest”标签的镜像。</p><p>下面来介绍一下如何从官方仓库拉取不同的镜像。</p><pre><code class="hljs plain">$ docker image pull mongo:3.3.11//该命令会从官方Mongo库拉取标签为3.3.11的镜像$ docker image pull redis:latest//该命令会从官方Redis库拉取标签为latest的镜像$ docker image pull alpine//该命令会从官方Alpine库拉取标签为latest的镜像</code></pre><p>关于上述命令,需要注意以下几点。</p><blockquote><p>首先,如果没有在仓库名称后指定具体的镜像标签,则 Docker 会假设用户希望拉取标签为 latest 的镜像。</p></blockquote><blockquote><p>其次,标签为 latest 的镜像没有什么特殊魔力!标有 latest 标签的镜像不保证这是仓库中最新的镜像!例如,Alpine 仓库中最新的镜像通常标签是 edge。通常来讲,使用 latest 标签时需要谨慎!</p></blockquote><p>从非官方仓库拉取镜像也是类似的,读者只需要在仓库名称面前加上 Docker Hub 的用户名或者组织名称。</p><p>下面通过示例来展示如何从 tu-demo 仓库中拉取 v2 这个镜像,其中镜像的拥有者是 Docker Hub 账户 nigelpoulton,一个不应该被信任的账户。</p><pre><code class="hljs plain">$ docker image pull nigelpoulton/tu-demo:v2//该命令会从以我自己的 Docker Hub 账号为命名空间的 tu-demo 库中下载标签为 v2 的镜像Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]Pull an image or a repository from a registryOptions: -a, --all-tags 下载在仓库里所有被标记的版本 --disable-content-trust 跳过镜像验证 (默认值 true) -q, --quiet 禁止输出详细信息</code></pre><p>如果希望从第三方镜像仓库服务获取镜像(非 Docker Hub),则需要在镜像仓库名称前加上第三方镜像仓库服务的 DNS 名称,私有仓库也是如此。</p><p>假设上面的示例中的镜像位于 Google 容器镜像仓库服务(GCR)中,则需要在仓库名称前面加上 gcr.io,如 docker pull gcr.io/nigelpoulton/tu-demo:v2(这个仓库和镜像并不存在)。</p><p>可能需要拥有第三方镜像仓库服务的账户,并在拉取镜像前完成登录。</p><h2 id="镜像查看"><a href="#镜像查看" class="headerlink" title="镜像查看"></a>镜像查看</h2><pre><code class="hljs shell">docker images : 列出本地镜像。<span class="hljs-meta">#</span><span class="bash"> 语法</span>docker images [OPTIONS] [REPOSITORY[:TAG]]OPTIONS说明:-a :列出本地所有的镜像(含中间映像层,默认情况下,过滤掉中间映像层);--digests :显示镜像的摘要信息;-f :显示满足条件的镜像; --format :指定返回值的模板文件; --no-trunc :显示完整的镜像信息;-q :只显示镜像ID。</code></pre><h3 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h3><p>查看本地镜像列表。</p><pre><code class="hljs plain">runoob@runoob:~$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmymysql v1 37af1236adef 5 minutes ago 329 MBrunoob/ubuntu v4 1c06aa18edee 2 days ago 142.1 MB<none> <none> 5c6e1090e771 2 days ago 165.9 MBhttpd latest ed38aaffef30 11 days ago 195.1 MBalpine latest 4e38e38c8ce0 2 weeks ago 4.799 MBmongo 3.2 282fd552add6 3 weeks ago 336.1 MBredis latest 4465e4bcad80 3 weeks ago 185.7 MBphp 5.6-fpm 025041cd3aa5 3 weeks ago 456.3 MBpython 3.5 045767ddf24a 3 weeks ago 684.1 MB</code></pre><blockquote><p>列出本地镜像中REPOSITORY为ubuntu的镜像列表。</p></blockquote><pre><code class="hljs plain">root@runoob:~# docker images ubuntuREPOSITORY TAG IMAGE ID CREATED SIZEubuntu 14.04 90d5884b1ee0 9 weeks ago 188 MBubuntu 15.10 4e3b13c8a266 3 months ago 136.3 MB</code></pre><h2 id="镜像删除"><a href="#镜像删除" class="headerlink" title="镜像删除"></a>镜像删除</h2><pre><code class="hljs plain">docker rmi : 删除本地一个或多少镜像。语法docker rmi [OPTIONS] IMAGE [IMAGE...]OPTIONS说明:-f :强制删除;--no-prune :不移除该镜像的过程镜像,默认移除;</code></pre><h3 id="实例-1"><a href="#实例-1" class="headerlink" title="实例"></a>实例</h3><blockquote><p>强制删除本地镜像 runoob/ubuntu:v4。</p></blockquote><pre><code class="hljs plain">root@root:~# docker rmi -f runoob/ubuntu:v4Untagged: runoob/ubuntu:v4Deleted: sha256:1c06aa18edee44230f93a90a7d88139235de12cd4c089d41eed8419b503072beDeleted: sha256:85feb446e89a28d58ee7d80ea5ce367eebb7cec70f0ec18aa4faa874cbd97c73</code></pre><p><img src="https://imgkr.cn-bj.ufileos.com/fdcbbcf4-900a-4a45-88bc-ff692333f8cf.png" srcset="/img/loading.gif" alt=""></p><p><img src="https://mmbiz.qpic.cn/mmbiz_gif/b96CibCt70iaZREh6DtDyA9wcDsp0m1RNV9C4uiaagltPDn83s3k6Sw5DbfRWdGc25Q1WDNCpjZLXQpCxFfiaGT5ag/640?wx_fmt=gif" srcset="/img/loading.gif" alt=""></p><h4 id="扫描二维码-获取更多精彩"><a href="#扫描二维码-获取更多精彩" class="headerlink" title="扫描二维码,获取更多精彩!!!"></a>扫描二维码,获取更多精彩!!!</h4><p><img src="https://imgkr.cn-bj.ufileos.com/0945fb03-10f1-43ae-9a69-985c287f57d8.png" srcset="/img/loading.gif" alt=""></p>]]></content>
<categories>
<category>docker</category>
</categories>
<tags>
<tag>docker</tag>
<tag>docker教程</tag>
<tag>原创</tag>
<tag>docker 镜像</tag>
</tags>
</entry>
</search>