{"id":134880,"date":"2020-07-08T02:32:09","date_gmt":"2020-07-07T18:32:09","guid":{"rendered":"http:\/\/4563.org\/?p=134880"},"modified":"2020-07-08T02:32:09","modified_gmt":"2020-07-07T18:32:09","slug":"dockerfile-%e5%a6%82%e4%bd%95%e4%bc%a0%e9%80%92%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f%e6%96%87%e4%bb%b6%e5%b9%b6%e6%89%a7%e8%a1%8c%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=134880","title":{"rendered":"Dockerfile \u5982\u4f55\u4f20\u9012\u73af\u5883\u53d8\u91cf\u6587\u4ef6\u5e76\u6267\u884c\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Dockerfile \u5982\u4f55\u4f20\u9012\u73af\u5883\u53d8\u91cf\u6587\u4ef6\u5e76\u6267\u884c\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zealinux <\/span>  <span><i><\/i> 8<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u542f\u52a8\u5bb9\u5668\u65f6 configMap \u6587\u4ef6 config-env.sh,\u6302\u8f7d\u5230 \/u\/app\/env<\/p>\n<pre><code>AA=123 BB=456 ...\u5927\u51e0\u5341\u6761... <\/code><\/pre>\n<p>\u6211\u5728 Dockerfile \u4e2d\u5199\u4e86<\/p>\n<pre><code>ENTRYPOINT [\"sh\", \"-c\", \"${WAIT_FOR} java -jar a.jar\"] <\/code><\/pre>\n<blockquote>\n<p>ENTRYPOINT \u6539\u6210\u4e86 CMD \u4e5f\u4e0d\u884c<\/p>\n<\/blockquote>\n<p>\u6211 K8s \u4f20\u9012\u7684\u65f6\u5019\u4f7f\u7528\uff1a<\/p>\n<pre><code>        env:         # NOT OK         - name: WAIT_FOR           value: \"source \/u\/app\/env\/config-env.sh &amp;&amp; \"  <\/code><\/pre>\n<p>\u5bb9\u5668\u5e94\u8be5\u662f\u542f\u52a8\u4e0d\u6210\u529f\uff0c\u4e0d\u505c\u91cd\u542f <em>CrashLoopBackOff<\/em><\/p>\n<p>\u7531\u4e8e\u5e73\u53f0\u9650\u5236\uff0c\u5c3d\u91cf\u4f7f\u7528<strong>configMap<\/strong>\u6302\u8f7d\u6587\u4ef6\u7684\u65b9\u5f0f\u3002 \u5982\u679c\u4e00\u6761\u4e00\u6761\u8bbe\u7f6e env\uff0c\u4e5f\u4e0d\u597d\u3002 \u56e0\u4e3a\u8fd9\u4e2a\u9700\u8981\u7532\u65b9\u4eba\u624b\u52a8\u4e00\u4e2a\u4e00\u4e2a\u6dfb\u52a0\u8fdb\u53bb\u3002 \uff08\u4ed6\u4eec\u4e0d\u7528\u539f\u59cb\u7684 kubectl \u7684 yaml \u6587\u4ef6\uff0c\u800c\u662f\u662f\u901a\u8fc7\u67d0\u5bb6\u7684 k8s \u5e73\u53f0\u7ba1\u7406 web \u64cd\u4f5c\uff09<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>8<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2472108\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Jirajine <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60 sh \u6267\u884c\u7684\u811a\u6b65\u91cc\u9762\u5b9a\u4e49\u7684\u53d8\u91cf\u5916\u9762\u662f\u770b\u4e0d\u5230\u7684\u3002<br \/>\u76f4\u63a5\u996e\u7528 env \u6587\u4ef6\u6216\u8005\u628a\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u548c\u7a0b\u5e8f\u542f\u52a8\u547d\u4ee4\u5199\u5230\u4e00\u4e2a launcher \u811a\u672c\u91cc\u9762\uff0c\u7136\u540e\u5165\u53e3\u76f4\u63a5\u542f\u52a8\u8fd9\u4e2a\u811a\u672c\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2472109\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yangbonis <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u770b\u4e0b oci \u7684 spec \u6587\u4ef6\u91cc entrypoint \u6216\u8005 cmd \u548c env \u7684\u89e3\u6790\u987a\u5e8f\uff0c\u5982\u679c env \u540e\u89e3\u6790\uff0c\u90a3\u4f60 entrypoint \u7684\u8bed\u53e5\u53ea\u80fd\u505a\u6210\u955c\u50cf\u91cc\u811a\u672c\uff0c\u7136\u540e sh \u90a3\u4e2a\u811a\u672c\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2472110\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yangbonis <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ef\u80fd\u52a0\u4e0a\u8f6c\u4e49\u5c31\u80fd\u7528\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2472111\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yangbonis <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd8\u6709\u4f60\u8fd9 souce \u7684 java \u5b50\u8fdb\u7a0b\u770b\u4e0d\u5230                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2472112\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : leimao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Dockerfile \u91cc\u9700\u8981\u6709\u76f8\u5e94\u58f0\u660e\u5427\uff1f<br \/>https:\/\/leimao.github.io\/blog\/Docker-Building-Arguments\/                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2472113\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : leimao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u597d\u610f\u601d\uff0c\u628a\u73af\u5883\u53d8\u91cf\u770b\u6210 argument \u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2472114\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : leimao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u8fc7\u4f60\u8fd9\u4e2a\uff0cinstead of using env, \u7528 argument \u5c31\u80fd\u770b\u7684\u5230\u53d8\u91cf\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2472115\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : luhuisicnu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             java \u542f\u52a8\u53c2\u6570\u91cc\u9762\u53ef\u4ee5\u52a0\u73af\u5883\u53d8\u91cf\uff0c -D                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Dockerfile \u5982\u4f55\u4f20\u9012\u73af\u5883&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/134880"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=134880"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/134880\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=134880"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=134880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}