{"id":2901,"date":"2017-10-15T13:58:07","date_gmt":"2017-10-15T05:58:07","guid":{"rendered":"http:\/\/switch.linesno.com\/?p=2901"},"modified":"2017-10-15T13:58:13","modified_gmt":"2017-10-15T05:58:13","slug":"jenkins-docker%e9%95%9c%e5%83%8f%e9%81%87%e5%88%b0%e7%9a%84volume%e6%9d%83%e9%99%90%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/switch.linesno.com\/?p=2901","title":{"rendered":"jenkins docker\u955c\u50cf\u9047\u5230\u7684volume\u6743\u9650\u95ee\u9898"},"content":{"rendered":"<p><img title=\"\" alt=\"image\" \/> \u5728\u6302\u5728\u6570\u636e\u5377\u7684\u65f6\u5019\u9047\u5230\u4e86\u6743\u9650\u95ee\u9898\uff0c\u5982\u4e0b\uff0c docker\u542f\u52a8\u547d\u4ee4<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs lasso has-numbering\">docker run <span class=\"hljs-attribute\">-d<\/span> <span class=\"hljs-attribute\">-v<\/span> \/root\/jenkins:\/<span class=\"hljs-built_in\">var<\/span>\/jenkins_home <span class=\"hljs-attribute\">-P<\/span> <span class=\"hljs-subst\">--<\/span>name jenkins<span class=\"hljs-attribute\">-server<\/span> jenkins<\/code><\/pre>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u770b\u4f3c\u6ca1\u6709\u4ec0\u4e48\u95ee\u9898\uff0c\u4f46\u5bb9\u5668\u5c31\u662f\u542f\u52a8\u4e0d\u8d77\u6765\uff0c\u6267\u884c<code>docker ps -a<\/code>\uff0c\u67e5\u770b<code>container<\/code>,\u5982\u4e0b\uff0c<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs ruby has-numbering\">[root<span class=\"hljs-variable\">@esslog<\/span>-shqs-<span class=\"hljs-number\">6<\/span> ~]<span class=\"hljs-comment\"># docker ps -a<\/span>\r\n<span class=\"hljs-constant\">CONTAINER<\/span> <span class=\"hljs-constant\">ID<\/span>        <span class=\"hljs-constant\">IMAGE<\/span>               <span class=\"hljs-constant\">COMMAND<\/span>                  <span class=\"hljs-constant\">CREATED<\/span>             <span class=\"hljs-constant\">STATUS<\/span>                     <span class=\"hljs-constant\">PORTS<\/span>               <span class=\"hljs-constant\">NAMES<\/span>\r\n<span class=\"hljs-number\">274<\/span>d92964edb        jenkins             <span class=\"hljs-string\">\"\/bin\/tini -- \/usr\/lo\"<\/span>   <span class=\"hljs-number\">2<\/span> minutes ago       <span class=\"hljs-constant\">Exited<\/span> (<span class=\"hljs-number\">1<\/span>) <span class=\"hljs-number\">2<\/span> minutes ago                       jenkins-server<\/code><\/pre>\n<p>\u63a5\u7740\u6267\u884c<code>docker logs jenkins-server<\/code>\u67e5\u770b<code>container<\/code>\u65e5\u5fd7\uff0c\u5982\u4e0b<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs lasso has-numbering\">Can <span class=\"hljs-literal\">not<\/span> write <span class=\"hljs-keyword\">to<\/span> \/<span class=\"hljs-built_in\">var<\/span>\/jenkins_home\/copy_reference_file<span class=\"hljs-built_in\">.<\/span><span class=\"hljs-keyword\">log<\/span><span class=\"hljs-built_in\">.<\/span> Wrong volume permissions<span class=\"hljs-subst\">?<\/span>\r\ntouch: cannot touch \u2018\/<span class=\"hljs-built_in\">var<\/span>\/jenkins_home\/copy_reference_file<span class=\"hljs-built_in\">.<\/span><span class=\"hljs-keyword\">log<\/span>\u2019: Permission denied<\/code><\/pre>\n<p>\u65e5\u5fd7\u4e2d\u51fa\u73b0\u4e86\u4e00\u4e2a<code>Permission denied<\/code>\u9519\u8bef\uff0c\uff0c\u4ee5\u6211\u76ee\u524d\u7684\u529f\u529b\u8fd8\u4e0d\u6e05\u695a\u662f\u4ec0\u4e48\u95ee\u9898\u9020\u6210\u7684\uff0c\u4f46\u662f\u5728<a href=\"https:\/\/yq.aliyun.com\/articles\/53990\" target=\"_blank\" rel=\"noopener\">\u8c08\u8c08Docker Volume \u4e4b\u6743\u9650\u7ba1\u7406<\/a>\u548c<a href=\"http:\/\/www.cnblogs.com\/99fu\/p\/6042744.html\" target=\"_blank\" rel=\"noopener\">\u6301\u7eed\u96c6\u6210\uff08Continuous integration\uff09<\/a>\u4e24\u7bc7\u535a\u5ba2\u4e2d\u627e\u5230\u4e86\u7b54\u6848\uff0c\u5728\u6267\u884c<code>docker run<\/code>\u547d\u4ee4\u7684\u65f6\u5019\u589e\u52a0\u4e00\u4e2a<code>-u<\/code>\u53c2\u6570\uff0c\u5982\u4e0b\u6539\u8fdb\u540e\u7684\u547d\u4ee4\uff0c<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs lasso has-numbering\">docker run <span class=\"hljs-attribute\">-d<\/span> <span class=\"hljs-attribute\">-v<\/span> \/root\/jenkins:\/<span class=\"hljs-built_in\">var<\/span>\/jenkins_home <span class=\"hljs-attribute\">-u<\/span> <span class=\"hljs-number\">0<\/span> <span class=\"hljs-attribute\">-P<\/span> <span class=\"hljs-subst\">--<\/span>name jenkins<span class=\"hljs-attribute\">-server<\/span> jenkins<\/code><\/pre>\n<p>\u8fd9\u547d\u4ee4\u7684\u610f\u601d\u662f\u8986\u76d6\u5bb9\u5668\u4e2d\u5185\u7f6e\u7684\u5e10\u53f7\uff0c\u8be5\u7528\u5916\u90e8\u4f20\u5165\uff0c\u8fd9\u91cc\u4f20\u5165<code>0<\/code>\u4ee3\u8868\u7684\u662froot\u5e10\u53f7Id\u3002\u8fd9\u6837\u518d\u542f\u52a8\u7684\u65f6\u5019\u5c31\u5e94\u8be5\u6ca1\u95ee\u9898\u4e86\u3002 \u5982\u679c\u6309\u7167\u4e0a\u9762\u505a\u8fd8\u662f\u51fa\u73b0<code>Permission denied<\/code>\u9519\u8bef\uff0c\u90a3\u4e48\u53ef\u4ee5\u68c0\u67e5\u4e00\u4e0b<code>selinux<\/code>\u72b6\u6001\uff0c\u5f00\u542f\u7684\u60c5\u51b5\u4e0b\u4f1a\u5bfc\u81f4\u4e00\u4e9b\u670d\u52a1\u5b89\u88c5\u3001\u4f7f\u7528\u4e0d\u6210\u529f\u3002 \u67e5\u770bselinux\u72b6\u6001\uff0c<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs applescript has-numbering\">[root@localhost ~]<span class=\"hljs-comment\"># sestatus  <\/span>\r\nSELinux status:                 enabled  \r\nSELinuxfs mount:                \/sys\/fs\/selinux  \r\nSELinux root directory:         \/etc\/selinux  \r\nLoaded policy <span class=\"hljs-property\">name<\/span>:             targeted  \r\nCurrent mode:                   enforcing  \r\nMode <span class=\"hljs-keyword\">from<\/span> config <span class=\"hljs-type\">file<\/span>:          enforcing  \r\nPolicy MLS status:              enabled  \r\nPolicy deny_unknown status:     allowed  \r\nMax kernel policy <span class=\"hljs-property\">version<\/span>:      <span class=\"hljs-number\">28<\/span><\/code><\/pre>\n<p>\u4e34\u65f6\u5173\u95ed\uff0c<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs ruby has-numbering\">[root<span class=\"hljs-variable\">@localhost<\/span> ~]<span class=\"hljs-comment\"># setenforce 0<\/span><\/code><\/pre>\n<p>\u6c38\u4e45\u5173\u95ed,\u53ef\u4ee5\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\/etc\/selinux\/config,\u5c06\u5176\u4e2dSELINUX\u8bbe\u7f6e\u4e3adisabled\uff0c\u5982\u4e0b\uff0c<\/p>\n<pre class=\"prettyprint\"><code class=\"hljs vala has-numbering\">[root@localhost ~]# cat \/etc\/selinux\/config   \r\n\r\n<span class=\"hljs-preprocessor\"># This file controls the state of SELinux on the system.  <\/span>\r\n<span class=\"hljs-preprocessor\"># SELINUX= can take one of these three values:  <\/span>\r\n<span class=\"hljs-preprocessor\">#     enforcing - SELinux security policy is enforced.  <\/span>\r\n<span class=\"hljs-preprocessor\">#     permissive - SELinux prints warnings instead of enforcing.  <\/span>\r\n<span class=\"hljs-preprocessor\">#     disabled - No SELinux policy is loaded.  <\/span>\r\n<span class=\"hljs-preprocessor\">#SELINUX=enforcing  <\/span>\r\nSELINUX=disabled  \r\n<span class=\"hljs-preprocessor\"># SELINUXTYPE= can take one of three two values:  <\/span>\r\n<span class=\"hljs-preprocessor\">#     targeted - Targeted processes are protected,  <\/span>\r\n<span class=\"hljs-preprocessor\">#     minimum - Modification of targeted policy. Only selected processes are protected.   <\/span>\r\n<span class=\"hljs-preprocessor\">#     mls - Multi Level Security protection.  <\/span>\r\nSELINUXTYPE=targeted\r\n\r\n[root@rdo ~]# sestatus  \r\nSELinux status:                 disabled<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6302\u5728\u6570\u636e\u5377\u7684\u65f6\u5019\u9047\u5230\u4e86\u6743\u9650\u95ee\u9898\uff0c\u5982\u4e0b\uff0c docker\u542f\u52a8\u547d\u4ee4 docker run -d -v \/root\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85],"tags":[],"class_list":["post-2901","post","type-post","status-publish","format-standard","hentry","category-document"],"_links":{"self":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts\/2901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2901"}],"version-history":[{"count":2,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts\/2901\/revisions"}],"predecessor-version":[{"id":2904,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=\/wp\/v2\/posts\/2901\/revisions\/2904"}],"wp:attachment":[{"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2901"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/switch.linesno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}