{"id":225999,"date":"2021-09-21T08:39:00","date_gmt":"2021-09-21T00:39:00","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=225999"},"modified":"2021-09-07T08:45:49","modified_gmt":"2021-09-07T00:45:49","slug":"dockerfile-commands","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/dockerfile-commands.html","title":{"rendered":"Dockerfile\u6587\u4ef6\u547d\u4ee4\u8be6\u89e3"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nDocker \u53ef\u4ee5\u901a\u8fc7\u8bfb\u53d6 Dockerfile \u4e2d\u7684\u6307\u4ee4\u81ea\u52a8\u6784\u5efa\u955c\u50cf\u3002Dockerfile \u662f\u4e00\u4e2a\u6587\u672c\u6587\u6863\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u7528\u6237\u521b\u5efa\u955c\u50cf\u7684\u6240\u6709\u547d\u4ee4\u548c\u8bf4\u660e\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u4e00\u3001 \u53d8\u91cf<\/strong><\/div>\n

\u53d8\u91cf\u7528 $variable_name \u6216\u8005 ${variable_name} \u8868\u793a\u3002<\/p>\n

    \n
  • \u00a0${variable:-word} \u8868\u793a\u5982\u679c variable \u8bbe\u7f6e\uff0c\u5219\u7ed3\u679c\u5c06\u662f\u8be5\u503c\u3002\u5982\u679c variable \u672a\u8bbe\u7f6e\uff0cword \u5219\u5c06\u662f\u7ed3\u679c\u3002<\/li>\n
  • \u00a0${variable:+word} \u8868\u793a\u5982\u679c variable \u8bbe\u7f6e\u5219\u4e3a word \u7ed3\u679c\uff0c\u5426\u5219\u4e3a\u7a7a\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n

    \u53d8\u91cf\u524d\u52a0 \\ \u53ef\u4ee5\u8f6c\u4e49\u6210\u666e\u901a\u5b57\u7b26\u4e32\uff1a\\$foo or \\${foo}\uff0c\u8868\u793a\u8f6c\u6362\u4e3a $foo \u548c ${foo} \u6587\u5b57\u3002<\/p>\n

    \u4e8c\u3001FROM<\/strong><\/div>\n

    \u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u7684\u6784\u5efa\u9636\u6bb5\uff0c\u5e76\u8bbe\u7f6e\u57fa\u7840\u955c\u50cf\uff1a<\/p>\n

    FROM\u00a0[--platform=<platform>]\u00a0<image>\u00a0[AS\u00a0<name>]\r\nFROM\u00a0[--platform=<platform>]\u00a0<image>[:<tag>]\u00a0[AS\u00a0<name>]\r\nFROM\u00a0[--platform=<platform>]\u00a0<image>[@<digest>]\u00a0[AS\u00a0<name>]<\/pre>\n
      \n
    • \u00a0\u5355\u4e2a Dockfile \u53ef\u4ee5\u591a\u6b21\u51fa\u73b0 FROM\uff0c\u4ee5\u4f7f\u7528\u4e4b\u524d\u7684\u6784\u5efa\u9636\u6bb5\u4f5c\u4e3a\u53e6\u4e00\u4e2a\u6784\u5efa\u9636\u6bb5\u7684\u4f9d\u8d56\u9879<\/li>\n
    • \u00a0AS name \u8868\u793a\u4e3a\u6784\u5efa\u9636\u6bb5\u547d\u540d\uff0c\u5728\u540e\u7eed FROM \u548c COPY --from=<name> \u8bf4\u660e\u4e2d\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u540d\u8bcd\uff0c\u5f15\u7528\u6b64\u9636\u6bb5\u6784\u5efa\u7684\u6620\u50cf<\/li>\n
    • \u00a0digest \u5176\u5b9e\u5c31\u662f\u5c31\u662f\u6839\u636e\u955c\u50cf\u5185\u5bb9\u4ea7\u751f\u7684\u4e00\u4e2a ID\uff0c\u53ea\u8981\u955c\u50cf\u7684\u5185\u5bb9\u4e0d\u53d8 digest \u4e5f\u4e0d\u4f1a\u53d8<\/li>\n
    • \u00a0tag \u6216 digest \u503c\u662f\u53ef\u9009\u7684\u3002\u5982\u679c\u60a8\u7701\u7565\u5176\u4e2d\u4efb\u4f55\u4e00\u4e2a\uff0c\u6784\u5efa\u5668\u9ed8\u8ba4\u4f7f\u7528\u4e00\u4e2a latest \u6807\u7b7e\u3002\u5982\u679c\u627e\u4e0d\u5230\u8be5 tag \u503c\uff0c\u6784\u5efa\u5668\u5c06\u8fd4\u56de\u9519\u8bef\u3002<\/li>\n
    • \u00a0--platform \u6807\u5fd7\u53ef\u7528\u4e8e\u5728 FROM \u5f15\u7528\u591a\u5e73\u53f0\u955c\u50cf\u7684\u60c5\u51b5\u4e0b\u6307\u5b9a\u5e73\u53f0\u3002\u4f8b\u5982\uff0clinux\/amd64\u3001linux\/arm64\u3001 \u6216 windows\/amd64\u3002<\/li>\n<\/ul>\n
      \u4e09\u3001RUN<\/strong><\/div>\n

      \u5c06\u5728\u5f53\u524d\u955c\u50cf\u4e4b\u4e0a\u7684\u65b0\u5c42\u4e2d\u6267\u884c\u547d\u4ee4\uff0c\u5728 docker build\u65f6\u8fd0\u884c\u3002<\/p>\n

      RUN\u00a0\/bin\/bash\u00a0-c\u00a0'source\u00a0$HOME\/.bashrc;\u00a0\\\r\necho\u00a0$HOME'<\/pre>\n

      RUN \u6709\u4e24\u79cd\u5f62\u5f0f\uff1a<\/p>\n

        \n
      • \u00a0RUN<command>\uff08shell \u5f62\u5f0f\uff0c\u547d\u4ee4\u5728 shell \u4e2d\u8fd0\u884c\uff0c\u9ed8\u8ba4 \/bin\/sh -c \u5728 Linux \u6216 cmd \/S \/CWindows \u4e0a\uff09<\/li>\n
      • \u00a0RUN [\"executable\", \"param1\", \"param2\"]\uff08\u6267\u884c\u5f62\u5f0f\uff09<\/li>\n<\/ul>\n

        \u8bf4\u660e\uff1a<\/p>\n

          \n
        • \u00a0\u53ef\u4ee5\u4f7f\u7528 \\\uff08\u53cd\u659c\u6760\uff09\u5c06\u5355\u4e2a RUN \u6307\u4ee4\u5ef6\u7eed\u5230\u4e0b\u4e00\u884c<\/li>\n
        • \u00a0RUN \u5728\u4e0b\u4e00\u6b21\u6784\u5efa\u671f\u95f4\uff0c\u6307\u4ee4\u7f13\u5b58\u4e0d\u4f1a\u81ea\u52a8\u5931\u6548\u3002\u53ef\u4ee5\u4f7f\u7528 --no-cache \u6807\u5fd7\u4f7f\u6307\u4ee4\u7f13\u5b58\u65e0\u6548<\/li>\n
        • \u00a0Dockerfile \u7684\u6307\u4ee4\u6bcf\u6267\u884c\u4e00\u6b21\u90fd\u4f1a\u5728 Docker \u4e0a\u65b0\u5efa\u4e00\u5c42\u3002\u6240\u4ee5\u8fc7\u591a\u65e0\u610f\u4e49\u7684\u5c42\uff0c\u4f1a\u9020\u6210\u955c\u50cf\u81a8\u80c0\u8fc7\u5927\uff0c\u53ef\u4ee5\u4f7f\u7528 && \u7b26\u53f7\u8fde\u63a5\u547d\u4ee4\uff0c\u8fd9\u6837\u6267\u884c\u540e\uff0c\u53ea\u4f1a\u521b\u5efa 1 \u5c42\u955c\u50cf<\/li>\n<\/ul>\n
          \u56db\u3001CMD<\/strong><\/div>\n

          \u8fd0\u884c\u7a0b\u5e8f\uff0c\u5728 docker run \u65f6\u8fd0\u884c\uff0c\u4f46\u662f\u548c run \u547d\u4ee4\u4e0d\u540c\uff0cRUN \u662f\u5728 docker build \u65f6\u8fd0\u884c\u3002<\/p>\n

          FROM\u00a0ubuntu\r\nCMD\u00a0[\"\/usr\/bin\/wc\",\"--help\"]<\/pre>\n

          \u652f\u6301\u4e09\u79cd\u683c\u5f0f\uff1a<\/p>\n

            \n
          • \u00a0CMD [\"executable\",\"param1\",\"param2\"] \u4f7f\u7528 exec \u6267\u884c\uff0c\u63a8\u8350\u65b9\u5f0f\uff1b<\/li>\n
          • \u00a0CMD command param1 param2 \u5728 \/bin\/sh \u4e2d\u6267\u884c\uff0c\u63d0\u4f9b\u7ed9\u9700\u8981\u4ea4\u4e92\u7684\u5e94\u7528\uff1b<\/li>\n
          • \u00a0CMD [\"param1\",\"param2\"] \u63d0\u4f9b\u7ed9 ENTRYPOINT \u7684\u9ed8\u8ba4\u53c2\u6570\u3002<\/li>\n<\/ul>\n

            \u6307\u5b9a\u542f\u52a8\u5bb9\u5668\u65f6\u6267\u884c\u7684\u547d\u4ee4\uff0c\u6bcf\u4e2a Dockerfile \u53ea\u80fd\u6709\u4e00\u6761 CMD \u547d\u4ee4\u3002\u5982\u679c\u6307\u5b9a\u4e86\u591a\u6761\u547d\u4ee4\uff0c\u53ea\u6709\u6700\u540e\u4e00\u6761\u4f1a\u88ab\u6267\u884c\u3002<\/p>\n

            \u5982\u679c\u7528\u6237\u542f\u52a8\u5bb9\u5668\u65f6\u5019\u6307\u5b9a\u4e86\u8fd0\u884c\u7684\u547d\u4ee4\uff0c\u5219\u4f1a\u8986\u76d6\u6389 CMD \u6307\u5b9a\u7684\u547d\u4ee4\u3002<\/p>\n

            \u4e94\u3001LABEL<\/strong><\/div>\n

            \u6dfb\u52a0\u5143\u6570\u636e\uff1a<\/p>\n

            LABEL\u00a0multi.label1=\"value1\"\u00a0\\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0multi.label2=\"value2\"\u00a0\\\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0other=\"value3\"<\/pre>\n
            \u516d\u3001EXPOSE<\/strong><\/div>\n
            EXPOSE\u00a0<port>\u00a0[<port>\/<protocol>...]<\/pre>\n

            Docker \u5bb9\u5668\u5728\u8fd0\u884c\u65f6\u4fa6\u542c\u6307\u5b9a\u7684\u7f51\u7edc\u7aef\u53e3\u3002\u53ef\u4ee5\u6307\u5b9a\u7aef\u53e3\u662f\u76d1\u542cTCP\u8fd8\u662fUDP\uff0c\u5982\u679c\u4e0d\u6307\u5b9a\u534f\u8bae\uff0c\u9ed8\u8ba4\u4e3aTCP\u3002<\/p>\n

            \u8be5 EXPOSE \u6307\u4ee4\u5b9e\u9645\u4e0a\u5e76\u672a\u53d1\u5e03\u7aef\u53e3\u3002\u8981\u5728\u8fd0\u884c\u5bb9\u5668\u65f6\u5b9e\u9645\u53d1\u5e03\u7aef\u53e3\uff0cdocker run -P \u6765\u53d1\u5e03\u548c\u6620\u5c04\u4e00\u4e2a\u6216\u591a\u4e2a\u7aef\u53e3\u3002<\/p>\n

            \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cEXPOSE \u5047\u5b9a TCP\u3002\u60a8\u8fd8\u53ef\u4ee5\u6307\u5b9a UDP\uff1a<\/p>\n

            EXPOSE\u00a080\/udp<\/pre>\n
            \u4e03\u3001ENV<\/strong><\/div>\n

            \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n

            ENV\u00a0<key>=<value>\u00a0...<\/pre>\n

            \u8bbe\u7f6e\u7684\u73af\u5883\u53d8\u91cf\u5c06\u6301\u7eed\u5b58\u5728\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 docker inspect \u6765\u67e5\u770b\u3002\u4f7f\u7528 docker run --env <key>=<value> \u6765\u66f4\u6539\u73af\u5883\u53d8\u91cf\u7684\u503c\u3002<\/p>\n

            \u5982\u679c\u73af\u5883\u53d8\u91cf\u53ea\u5728\u6784\u5efa\u671f\u95f4\u9700\u8981\uff0c\u8bf7\u8003\u8651\u4e3a\u5355\u4e2a\u547d\u4ee4\u8bbe\u7f6e\u4e00\u4e2a\u503c\uff1a<\/p>\n

            RUN\u00a0DEBIAN_FRONTEND=noninteractive\u00a0apt-get\u00a0update\u00a0&&\u00a0apt-get\u00a0install\u00a0-y\u00a0...<\/pre>\n

            \u6216\u8005\u4f7f\u7528 ARG\uff0c\u5b83\u4e0d\u4f1a\u4fdd\u7559\u5728\u6700\u7ec8\u955c\u50cf\u4e2d\uff1a<\/p>\n

            ARG\u00a0DEBIAN_FRONTEND=noninteractive\r\nRUN\u00a0apt-get\u00a0update\u00a0&&\u00a0apt-get\u00a0install\u00a0-y\u00a0...<\/pre>\n
            \u516b\u3001ADD<\/strong><\/div>\n

            \u590d\u5236\u65b0\u6587\u4ef6\u3001\u76ee\u5f55\u6216\u8fdc\u7a0b\u6587\u4ef6 URL <src> \uff0c\u5e76\u5c06\u5b83\u4eec\u6dfb\u52a0\u5230 <dest> \u4e2d\u3002<\/p>\n

            <src> \u53ef\u4ee5\u6307\u5b9a\u591a\u4e2a\u8d44\u6e90\uff0c\u4f46\u5982\u679c\u5b83\u4eec\u662f\u6587\u4ef6\u6216\u76ee\u5f55\uff0c\u5219\u5b83\u4eec\u7684\u8def\u5f84\u88ab\u89e3\u91ca\u4e3a\u76f8\u5bf9\u4e8e\u6784\u5efa\u4e0a\u4e0b\u6587\u7684\u6e90\uff0c\u4e5f\u5c31\u662f WORKDIR\u3002<\/p>\n

            \u6bcf\u4e2a\u90fd <src> \u53ef\u80fd\u5305\u542b\u901a\u914d\u7b26\uff0c\u5339\u914d\u5c06\u4f7f\u7528 Go \u7684 filepath.Match \u89c4\u5219\u3002\u4f8b\u5982\uff1a<\/p>\n

            \u6dfb\u52a0\u6240\u6709\u4ee5\u201chom\u201d\u5f00\u5934\u7684\u6587\u4ef6\uff1a<\/p>\n

            ADD\u00a0hom*\u00a0\/mydir\/<\/pre>\n

            \u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\uff0c? \u88ab\u66ff\u6362\u4e3a\u4efb\u4f55\u5355\u4e2a\u5b57\u7b26\uff0c\u4f8b\u5982\u201chome.txt\u201d\u3002<\/p>\n

            ADD\u00a0hom?.txt\u00a0\/mydir\/<\/pre>\n

            <dest> \u662f\u4e00\u4e2a\u7edd\u5bf9\u8def\u5f84\uff0c\u6216\u76f8\u5bf9 WORKDIR \u7684\u76f8\u5bf9\u8def\u5f84\u3002<\/p>\n

            \u4e5d\u3001COPY<\/strong><\/div>\n

            \u8bed\u6cd5\u540cADD\u4e00\u81f4\uff0c\u590d\u5236\u62f7\u8d1d\u6587\u4ef6\u3002<\/p>\n

            COPY \u6307\u4ee4\u548c ADD \u6307\u4ee4\u7684\u552f\u4e00\u533a\u522b\u5728\u4e8e\uff1a\u662f\u5426\u652f\u6301\u4ece\u8fdc\u7a0bURL\u83b7\u53d6\u8d44\u6e90\u3002COPY \u6307\u4ee4\u53ea\u80fd\u4ece\u6267\u884c docker build \u6240\u5728\u7684\u4e3b\u673a\u4e0a\u8bfb\u53d6\u8d44\u6e90\u5e76\u590d\u5236\u5230\u955c\u50cf\u4e2d\u3002\u800c ADD \u6307\u4ee4\u8fd8\u652f\u6301\u901a\u8fc7 URL \u4ece\u8fdc\u7a0b\u670d\u52a1\u5668\u8bfb\u53d6\u8d44\u6e90\u5e76\u590d\u5236\u5230\u955c\u50cf\u4e2d\u3002<\/p>\n

            \u76f8\u540c\u9700\u6c42\u65f6\uff0c\u63a8\u8350\u4f7f\u7528 COPY \u6307\u4ee4\u3002ADD \u6307\u4ee4\u66f4\u64c5\u957f\u8bfb\u53d6\u672c\u5730tar\u6587\u4ef6\u5e76\u89e3\u538b\u7f29\u3002<\/p>\n

            \u5341\u3001ENTRYPOINT<\/strong><\/div>\n

            ENTRYPOINT \u548c CMD \u4e00\u6837\uff0c\u90fd\u662f\u5728\u6307\u5b9a\u5bb9\u5668\u542f\u52a8\u7a0b\u5e8f\u53ca\u53c2\u6570\uff0c\u4e0d\u8fc7\u5b83\u4e0d\u4f1a\u88ab docker run \u7684\u547d\u4ee4\u884c\u53c2\u6570\u6307\u5b9a\u7684\u6307\u4ee4\u6240\u8986\u76d6\u3002\u5982\u679c\u8981\u8986\u76d6\u7684\u8bdd\uff0c\u9700\u8981\u901a\u8fc7 docker run --entrypoint \u6765\u6307\u5b9a\u3002<\/p>\n

            \u5b83\u67092\u79cd\u683c\u5f0f\uff1a<\/p>\n

            ENTRYPOINT\u00a0[\"executable\",\u00a0\"param1\",\u00a0\"param2\"]\r\nENTRYPOINT\u00a0command\u00a0param1\u00a0param2<\/pre>\n

            \u6307\u5b9a\u4e86 ENTRYPOINT \u540e\uff0c CMD \u7684\u5185\u5bb9\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9 ENTRYPOINT \u6307\u4ee4\uff0c\u5b9e\u9645\u6267\u884c\u65f6\uff0c\u5c06\u53d8\u4e3a\uff1a<\/p>\n

            <ENTRYPOINT>\u00a0<CMD><\/pre>\n
            \u5341\u4e00\u3001VOLUME<\/strong><\/div>\n

            \u521b\u5efa\u4e00\u4e2a\u5177\u6709\u6307\u5b9a\u540d\u79f0\u7684\u6302\u8f7d\u6570\u636e\u5377\u3002<\/p>\n

            VOLUME\u00a0[\"\/var\/log\/\"]\r\nVOLUME\u00a0\/var\/log<\/pre>\n

            \u5b83\u7684\u4e3b\u8981\u4f5c\u7528\u662f\uff1a<\/p>\n

              \n
            • \u00a0\u907f\u514d\u91cd\u8981\u7684\u6570\u636e\uff0c\u56e0\u5bb9\u5668\u91cd\u542f\u800c\u4e22\u5931<\/li>\n
            • \u00a0\u907f\u514d\u5bb9\u5668\u4e0d\u65ad\u53d8\u5927<\/li>\n<\/ul>\n
              \u5341\u4e8c\u3001ARG<\/strong><\/div>\n

              \u5b9a\u4e49\u53d8\u91cf\uff0c\u4e0e ENV \u4f5c\u7528\u76f8\u540c\uff0c\u4e0d\u8fc7 ARG \u53d8\u91cf\u4e0d\u4f1a\u50cf ENV \u53d8\u91cf\u90a3\u6837\u6301\u4e45\u5316\u5230\u6784\u5efa\u597d\u7684\u955c\u50cf\u4e2d\u3002<\/p>\n

              ARG\u00a0<name>[=<default\u00a0value>]<\/pre>\n

              Docker \u6709\u4e00\u7ec4\u9884\u5b9a\u4e49\u7684 ARG \u53d8\u91cf\uff0c\u60a8\u53ef\u4ee5\u5728 Dockerfile \u4e2d\u6ca1\u6709\u76f8\u5e94\u6307\u4ee4\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u8fd9\u4e9b\u53d8\u91cf\u3002<\/p>\n

                \n
              • \u00a0HTTP_PROXY<\/li>\n
              • \u00a0http_proxy<\/li>\n
              • \u00a0HTTPS_PROXY<\/li>\n
              • \u00a0https_proxy<\/li>\n
              • \u00a0FTP_PROXY<\/li>\n
              • \u00a0ftp_proxy<\/li>\n
              • \u00a0NO_PROXY<\/li>\n
              • \u00a0no_proxy<\/li>\n<\/ul>\n

                \u8981\u4f7f\u7528\u8fd9\u4e9b\uff0c\u8bf7\u4f7f\u7528 --build-arg \u6807\u5fd7\u5728\u547d\u4ee4\u884c\u4e0a\u4f20\u9012\u5b83\u4eec\uff0c\u4f8b\u5982\uff1a<\/p>\n

                docker\u00a0build\u00a0--build-arg\u00a0HTTPS_PROXY=https:\/\/my-proxy.example.com\u00a0.<\/pre>\n
                \u5341\u4e09\u3001ONBUILD<\/strong><\/div>\n

                \u5c06\u4e00\u4e2a\u89e6\u53d1\u6307\u4ee4\u6dfb\u52a0\u5230\u955c\u50cf\u4e2d\uff0c\u4ee5\u4fbf\u7a0d\u540e\u5728\u8be5\u955c\u50cf\u7528\u4f5c\u53e6\u4e00\u4e2a\u6784\u5efa\u7684\u57fa\u7840\u65f6\u6267\u884c\u3002\u4e5f\u5c31\u662f\u53e6\u5916\u4e00\u4e2a dockerfile FROM \u4e86\u8fd9\u4e2a\u955c\u50cf\u7684\u65f6\u5019\u6267\u884c\u3002<\/p>\n

                ONBUILD\u00a0ADD\u00a0.\u00a0\/app\/src\r\nONBUILD\u00a0RUN\u00a0\/usr\/local\/bin\/python-build\u00a0--dir\u00a0\/app\/src<\/pre>\n
                \u5341\u56db\u3001STOPSIGNAL<\/strong><\/div>\n

                \u8bbe\u7f6e\u5c06\u53d1\u9001\u5230\u5bb9\u5668\u9000\u51fa\u7684\u7cfb\u7edf\u8c03\u7528\u4fe1\u53f7\u3002\u8be5\u4fe1\u53f7\u53ef\u4ee5\u662f\u4e0e\u5185\u6838\u7cfb\u7edf\u8c03\u7528\u8868\u4e2d\u7684\u4f4d\u7f6e\u5339\u914d\u7684\u6709\u6548\u65e0\u7b26\u53f7\u6570\uff0c\u4f8b\u5982 9\uff0c\u6216\u683c\u5f0f\u4e3a SIGNAME \u7684\u4fe1\u53f7\u540d\u79f0\uff0c\u4f8b\u5982 SIGKILL\u3002<\/p>\n

                STOPSIGNAL\u00a0signal<\/pre>\n

                \u9ed8\u8ba4\u7684 stop-signal \u662f SIGTERM\uff0c\u5728 docker stop \u7684\u65f6\u5019\u4f1a\u7ed9\u5bb9\u5668\u5185 PID \u4e3a 1 \u7684\u8fdb\u7a0b\u53d1\u9001\u8fd9\u4e2a signal\uff0c\u901a\u8fc7 --stop-signal \u53ef\u4ee5\u8bbe\u7f6e\u81ea\u5df1\u9700\u8981\u7684 signal\uff0c\u4e3b\u8981\u76ee\u7684\u662f\u4e3a\u4e86\u8ba9\u5bb9\u5668\u5185\u7684\u5e94\u7528\u7a0b\u5e8f\u5728\u63a5\u6536\u5230 signal \u4e4b\u540e\u53ef\u4ee5\u5148\u5904\u7406\u4e00\u4e9b\u4e8b\u7269\uff0c\u5b9e\u73b0\u5bb9\u5668\u7684\u5e73\u6ed1\u9000\u51fa\uff0c\u5982\u679c\u4e0d\u505a\u4efb\u4f55\u5904\u7406\uff0c\u5bb9\u5668\u5c06\u5728\u4e00\u6bb5\u65f6\u95f4\u4e4b\u540e\u5f3a\u5236\u9000\u51fa\uff0c\u4f1a\u9020\u6210\u4e1a\u52a1\u7684\u5f3a\u5236\u4e2d\u65ad\uff0c\u9ed8\u8ba4\u65f6\u95f4\u662f 10s\u3002<\/p>\n

                \u5341\u4e94\u3001HEALTHCHECK<\/strong><\/div>\n

                \u7528\u4e8e\u6307\u5b9a\u67d0\u4e2a\u7a0b\u5e8f\u6216\u8005\u6307\u4ee4\u6765\u76d1\u63a7 Docker \u5bb9\u5668\u670d\u52a1\u7684\u8fd0\u884c\u72b6\u6001\u3002\u8be5 HEALTHCHECK \u6307\u4ee4\u6709\u4e24\u79cd\u5f62\u5f0f\uff1a<\/p>\n

                  \n
                • \u00a0HEALTHCHECK [OPTIONS] CMD command\uff08\u901a\u8fc7\u5728\u5bb9\u5668\u5185\u8fd0\u884c\u547d\u4ee4\u6765\u68c0\u67e5\u5bb9\u5668\u5065\u5eb7\u72b6\u51b5\uff09<\/li>\n
                • \u00a0HEALTHCHECK NONE\uff08\u7981\u7528\u4ece\u57fa\u7840\u955c\u50cf\u7ee7\u627f\u7684\u4efb\u4f55\u5065\u5eb7\u68c0\u67e5\uff09<\/li>\n<\/ul>\n
                  \u5341\u516d\u3001SHELL<\/strong><\/div>\n

                  \u8986\u76d6\u7528\u4e8e\u547d\u4ee4\u7684 shell \u5f62\u5f0f\u7684\u9ed8\u8ba4 shell\u3002Linux \u4e0a\u7684\u9ed8\u8ba4 shell \u662f [\"\/bin\/sh\", \"-c\"]\uff0cWindows \u4e0a\u662f [\"cmd\", \"\/S\", \"\/C\"]\u3002<\/p>\n

                  SHELL\u00a0[\"executable\",\u00a0\"parameters\"]<\/pre>\n

                  \u8be5 SHELL \u6307\u4ee4\u5728 Windows \u4e0a\u7279\u522b\u6709\u7528\uff0c\u56e0\u4e3a Windows \u6709\u4e24\u79cd\u5e38\u7528\u4e14\u622a\u7136\u4e0d\u540c\u7684\u672c\u673a SHELL\uff1acmd \u548c powershell\uff0c\u4ee5\u53ca\u53ef\u7528\u7684\u5907\u7528 shell\uff0c\u5305\u62ec sh\u3002\u8be5 SHELL \u6307\u4ee4\u53ef\u4ee5\u51fa\u73b0\u591a\u6b21\u3002\u6bcf\u6761 SHELL \u6307\u4ee4\u90fd\u4f1a\u8986\u76d6\u6240\u6709\u5148\u524d\u7684 SHELL \u6307\u4ee4\uff0c\u5e76\u5f71\u54cd\u6240\u6709\u540e\u7eed\u6307\u4ee4\u3002<\/p>\n

                  \u5341\u4e03\u3001WORKDIR<\/strong><\/div>\n

                  \u5de5\u4f5c\u76ee\u5f55\uff0c\u5982\u679c WORKDIR \u4e0d\u5b58\u5728\uff0c\u5373\u4f7f\u5b83\u6ca1\u6709\u5728\u540e\u7eed Dockerfile \u6307\u4ee4\u4e2d\u4f7f\u7528\uff0c\u5b83\u4e5f\u4f1a\u88ab\u521b\u5efa\u3002<\/p>\n

                  docker build \u6784\u5efa\u955c\u50cf\u8fc7\u7a0b\u4e2d\uff0c\u6bcf\u4e00\u4e2a RUN \u547d\u4ee4\u90fd\u4f1a\u65b0\u5efa\u4e00\u5c42\u3002\u53ea\u6709\u901a\u8fc7 WORKDIR \u521b\u5efa\u7684\u76ee\u5f55\u624d\u4f1a\u4e00\u76f4\u5b58\u5728\u3002<\/p>\n

                  \u53ef\u4ee5\u8bbe\u7f6e\u591a\u4e2a WORKDIR\uff0c\u5982\u679c\u63d0\u4f9b\u4e86\u76f8\u5bf9\u8def\u5f84\uff0c\u5b83\u5c06\u76f8\u5bf9\u4e8e\u524d\u4e00\u6761 WORKDIR \u6307\u4ee4\u7684\u8def\u5f84\u3002\u4f8b\u5982\uff1a<\/p>\n

                  WORKDIR\u00a0\/a\r\nWORKDIR\u00a0b\r\nWORKDIR\u00a0c\r\nRUN\u00a0pwd<\/pre>\n

                  \u6700\u7ec8 pwd \u547d\u4ee4\u7684\u8f93\u51fa\u662f \/a\/b\/c\u3002<\/p>\n

                  \u8be5 WORKDIR \u6307\u4ee4\u53ef\u4ee5\u89e3\u6790\u5148\u524d\u4f7f\u7528 ENV\uff0c\u4f8b\u5982\uff1a<\/p>\n

                  ENV\u00a0DIRPATH=\/path\r\nWORKDIR\u00a0$DIRPATH\/$DIRNAME\r\nRUN\u00a0pwd<\/pre>\n

                  \u6700\u7ec8 pwd \u547d\u4ee4\u7684\u8f93\u51fa\u662f \/path\/$DIRNAME\u3002<\/p>\n

                  \u5341\u516b\u3001USER<\/strong><\/div>\n

                  \u8bbe\u7f6e\u7528\u6237\u540d\uff08\u6216 UID\uff09\u548c\u53ef\u9009\u7684\u7528\u6237\u7ec4\uff08\u6216 GID\uff09\u3002<\/p>\n

                  USER\u00a0<user>[:<group>]\r\nUSER\u00a0<UID>[:<GID>]<\/pre>\n","protected":false},"excerpt":{"rendered":"

                  \u53d8\u91cf\u7528 $variable_name \u6216\u8005 ${variable_name} \u8868\u793a\u3002 \u00a0${variable: […]<\/p>\n","protected":false},"author":323,"featured_media":110911,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-225999","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/225999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=225999"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/225999\/revisions"}],"predecessor-version":[{"id":226013,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/225999\/revisions\/226013"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/110911"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=225999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=225999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=225999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}