正在免费适用着Aliyun主机,当然要用docker来部署我的服务器啦。但是今天碰到了题目的问题,细节如下:
<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># docker info</span> FATA[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0000</span>] Cannot connect <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">to</span> <span class="hljs-operator" style="box-sizing: border-box;">the</span> Docker daemon. Is <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'docker -d'</span> running <span class="hljs-command" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">on</span> <span class="hljs-title" style="box-sizing: border-box;">this</span> <span class="hljs-title" style="box-sizing: border-box;">host</span>? </span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># docker -d</span> INFO[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0000</span>] +job serveapi(unix:<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">///var/run/docker.sock) </span> FATA[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0000</span>] pid <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">file</span> found, ensure docker is <span class="hljs-operator" style="box-sizing: border-box;">not</span> running <span class="hljs-operator" style="box-sizing: border-box;">or</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">delete</span> /var/run/docker.pid </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li></ul>
首先要查看docker daemon是否在运行。
<code class="hljs axapta has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;"># ps aux | grep docker</span> root <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">691</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.6</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">506388</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">17068</span> ? Ssl Mar07 <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">45</span> /usr/bin/docker -d root <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1330</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.8</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">124088</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">8392</span> ? Sl Mar07 <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">01</span> docker-proxy -proto tcp -host-ip <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span> -host-port <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">80</span> -<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">container</span>-ip <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">192.168</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.42</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.2</span> -<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">container</span>-port <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">80</span> root <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9607</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11720</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">896</span> pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> S+ <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">50</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> grep --color=auto docker</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul>
这样看来,docker deamon正在运行,但是报此错误实属不应该。那么将其停止,再启动。
<code class="hljs vala has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;"># service docker stop</span> <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;"># ps aux | grep docker</span> root <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9624</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">11716</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">636</span> pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span> S+ <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">16</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">52</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> grep --color=auto docker <span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;"># docker -d</span> INFO[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0000</span>] +job serveapi(unix:<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">///var/run/docker.sock) </span> INFO[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0000</span>] Listening <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span><span class="hljs-constant" style="box-sizing: border-box;"> HTTP </span>on unix (/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">var</span>/run/docker.sock) INFO[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0000</span>] +job init_networkdriver() INFO[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0000</span>] -job init_networkdriver() =<span class="hljs-constant" style="box-sizing: border-box;"> OK </span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>) INFO[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0000</span>] WARNING: Your kernel does not support cgroup swap limit. INFO[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0000</span>] Loading containers: start. .......... INFO[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0001</span>] Loading containers: done. INFO[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0001</span>] docker daemon: <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.5</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span> a8a31ef; execdriver: native-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.2</span>; graphdriver: aufs INFO[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0001</span>] +job acceptconnections() INFO[<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0001</span>] -job acceptconnections() =<span class="hljs-constant" style="box-sizing: border-box;"> OK </span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>) </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li></ul>
好吧,最有趣的事情是,之前我在root下一切运行良好,但是现在就像见鬼一样遇到上面的问题。上述的工作完成后,仍有问题。最后我使用sudo竟然解决了问题。如下:
<code class="hljs vala has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;"># sudo docker info</span> Containers: <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span> Images: <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">32</span> Storage Driver: aufs Root Dir: /<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">var</span>/lib/docker/aufs Backing Filesystem: extfs Dirs: <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">42</span> Execution Driver: native-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.2</span> Kernel Version: <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.13</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">32</span>-generic Operating System: Ubuntu <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">14.04</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.1</span> LTS</code>