{"id":74,"date":"2026-08-02T22:33:42","date_gmt":"2026-08-02T14:33:42","guid":{"rendered":"https:\/\/blog-1501514697.top\/?p=74"},"modified":"2026-08-23T12:35:10","modified_gmt":"2026-08-23T04:35:10","slug":"%e5%88%9d%e5%ad%a6docker%ef%bc%8c%e8%ae%b0%e5%bd%95%e4%b8%80%e4%ba%9b%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5%e5%92%8c%e4%bd%bf%e7%94%a8%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/blog-1501514697.top\/?p=74","title":{"rendered":"\u521d\u5b66Docker\uff0c\u8bb0\u5f55\u4e00\u4e9b\u57fa\u672c\u6982\u5ff5\u548c\u4f7f\u7528\u65b9\u5f0f"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u4e3a\u4ec0\u4e48\u4f7f\u7528 Docker \u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\uff1f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f20\u7edf\u90e8\u7f72\u65b9\u5f0f\u901a\u5e38\u6bd4\u8f83\u590d\u6742\uff0c\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\u65f6\u9700\u8981\u624b\u52a8\u914d\u7f6e\u8fd0\u884c\u73af\u5883\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b89\u88c5\u5bf9\u5e94\u7248\u672c\u7684 JDK<\/li>\n\n\n\n<li>\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/li>\n\n\n\n<li>\u5b89\u88c5 Maven \u7b49\u6784\u5efa\u5de5\u5177<\/li>\n\n\n\n<li>\u5904\u7406\u4e0d\u540c\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u73af\u5883\u5dee\u5f02<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f7f\u7528 Docker\uff0c\u53ef\u4ee5\u5b9e\u73b0<strong>\u201c\u6784\u5efa\u4e00\u6b21\u955c\u50cf\uff0c\u5230\u5904\u8fd0\u884c\u201d<\/strong>\uff0c\u5c06\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u73af\u5883\u4e00\u8d77\u6253\u5305\uff0c\u907f\u514d\u7e41\u7410\u7684\u624b\u5de5\u914d\u7f6e\uff0c\u63d0\u9ad8\u90e8\u7f72\u6548\u7387\u548c\u73af\u5883\u4e00\u81f4\u6027\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001Docker \u57fa\u672c\u6982\u5ff5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Docker \u955c\u50cf\uff08Image\uff09<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Docker \u955c\u50cf\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u9759\u6001\u6587\u4ef6\uff0c\u7c7b\u4f3c\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684\u5b89\u88c5\u5305\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u5e38\u901a\u8fc7 Dockerfile \u6587\u4ef6\u6784\u5efa\u751f\u6210\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker build -t spring-application .<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Docker \u5bb9\u5668\uff08Container\uff09<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Docker \u5bb9\u5668\u662f\u955c\u50cf\u8fd0\u884c\u540e\u7684\u5b9e\u4f8b\uff0c\u662f\u5e94\u7528\u7a0b\u5e8f\u771f\u6b63\u8fd0\u884c\u7684\u5730\u65b9\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u955c\u50cf\uff1a<\/strong>\u76f8\u5f53\u4e8e\u98df\u8c31\uff0c\u63cf\u8ff0\u4e86\u5982\u4f55\u5236\u4f5c\u83dc\u80b4\u3002<\/li>\n\n\n\n<li><strong>\u5bb9\u5668\uff1a<\/strong>\u76f8\u5f53\u4e8e\u6839\u636e\u98df\u8c31\u5236\u4f5c\u51fa\u6765\u7684\u83dc\u80b4\uff0c\u662f\u5b9e\u9645\u8fd0\u884c\u7684\u5b9e\u4f8b\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. Docker \u4ed3\u5e93\uff08<strong>Registries<\/strong>\uff09<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Docker \u4ed3\u5e93\u662f\u5b58\u50a8 Docker \u955c\u50cf\u7684\u5730\u65b9\uff0c\u5982 Docker Hub\uff0c\u4f60\u53ef\u4ee5\u4eceDocker Hub\u4e0b\u8f7d\u522b\u4eba\u5236\u4f5c\u597d\u7684\u955c\u50cf\u4f9b\u81ea\u5df1\u4f7f\u7528\uff0c\u4e5f\u53ef\u4ee5\u4e0a\u4f20\u81ea\u5df1\u5236\u4f5c\u7684\u955c\u50cf\u5230Docker Hub\u4f9b\u4ed6\u4eba\u4e0b\u8f7d\u4f7f\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u60f3\u8981\u79c1\u6709\u5316Docker\u4ed3\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528Harbor\u6765\u5b9e\u73b0\u79c1\u6709\u5316\u90e8\u7f72\uff0c\u90e8\u7f72\u540e\u53ef\u4ee5\u5b58\u50a8\u548c\u4f7f\u7528\u81ea\u5df1\u5185\u90e8\u5236\u4f5c\u7684Docker\u955c\u50cf\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001Docker \u5e38\u7528\u57fa\u7840\u547d\u4ee4<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u6784\u5efa Docker \u955c\u50cf<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5b58\u653e Dockerfile \u7684\u76ee\u5f55\u4e0b\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6784\u5efa Docker \u955c\u50cf\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker build -t spring-application .<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u67e5\u770b Docker \u955c\u50cf\u4fe1\u606f<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>docker images<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u8fd0\u884c Docker \u5bb9\u5668<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d -p 8080:8080 spring-application<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u67e5\u770b\u8fd0\u884c\u4e2d\u7684\u5bb9\u5668\u4fe1\u606f<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>docker ps<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u505c\u6b62 Docker \u5bb9\u5668<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><pre class=\"wp-block-code\"><code>docker stop [container id]<\/code><\/pre><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u67e5\u770b\u672a\u8fd0\u884c\u7684 Docker \u5bb9\u5668<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><pre class=\"wp-block-code\"><code>docker ps -a<\/code><\/pre><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. \u5220\u9664 Docker \u5bb9\u5668<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><pre class=\"wp-block-code\"><code>docker rm [container id]<\/code><\/pre><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. \u6e05\u9664 Docker \u6784\u5efa\u7f13\u5b58<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>docker builder prune<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001Dockerfile \u6587\u4ef6\u89e3\u6790<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4ee5\u4e00\u4e2a Spring Boot \u9879\u76ee\u4e3a\u4f8b\uff0c\u4ecb\u7ecd Dockerfile \u6587\u4ef6\u4e2d\u7684\u5e38\u7528\u914d\u7f6e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u6307\u5b9a\u57fa\u7840\u955c\u50cf<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># \u7b2c\u4e00\u9636\u6bb5\u8d1f\u8d23\u4f7f\u7528\u4e00\u4e2a\u5e26\u6709 Maven 3.9 \u548c JDK 21 \u7684 Linux \u73af\u5883\u6765\u7f16\u8bd1 jar \u5305\nFROM maven:3.9-eclipse-temurin-21 AS builder<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u4f7f\u7528 Maven + JDK 21 \u7684\u57fa\u7840\u955c\u50cf\u4f5c\u4e3a\u6784\u5efa\u73af\u5883\uff0c\u5e76\u547d\u540d\u5f53\u524d\u9636\u6bb5\u4e3a <code>builder<\/code>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u8bbe\u7f6e\u5de5\u4f5c\u76ee\u5f55<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5c06 Docker \u5bb9\u5668\u5185\u7684\u5de5\u4f5c\u76ee\u5f55\u8bbe\u7f6e\u4e3a \/build\uff0c\u5e76\u5207\u6362\u5230 build \u76ee\u5f55\n# \u7c7b\u4f3c Linux \u4e2d\u6267\u884c cd \/build\nWORKDIR \/build<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u590d\u5236\u9879\u76ee\u6e90\u7801<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># \u590d\u5236\u9879\u76ee\u6e90\u7801\u548c\u8d44\u6e90\u6587\u4ef6\n# \u4ece\u5bbf\u4e3b\u673a\u5f53\u524d\u76ee\u5f55\u590d\u5236\u5230 Docker \u5bb9\u5668\u5185\u7684 \/build \u76ee\u5f55\n# \u5982\u679c\u5b58\u5728 .dockerignore \u6587\u4ef6\uff0c\u4f1a\u6392\u9664\u5176\u4e2d\u6307\u5b9a\u7684\u5185\u5bb9\nCOPY . .<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u4f7f\u7528 Maven \u7f16\u8bd1\u9879\u76ee<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4f7f\u7528 Java 21 \u7f16\u8bd1\u6240\u6709\u4f9d\u8d56\u6a21\u5757\uff0c\u5e76\u751f\u6210 admin\/target\/admin.jar\nRUN mvn -B -ntp -pl admin -am clean package -DskipTests<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u547d\u4ee4\u4f1a\u6267\u884c Maven \u6784\u5efa\u6d41\u7a0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>clean\uff1a\u6e05\u7406\u4e4b\u524d\u7684\u6784\u5efa\u6587\u4ef6<\/li>\n\n\n\n<li>package\uff1a\u6267\u884c\u9879\u76ee\u7f16\u8bd1\u5e76\u751f\u6210 jar \u5305<\/li>\n\n\n\n<li>-pl admin\uff1a\u6307\u5b9a\u6784\u5efa admin \u6a21\u5757<\/li>\n\n\n\n<li>-am\uff1a\u540c\u65f6\u6784\u5efa admin \u4f9d\u8d56\u7684\u5176\u4ed6\u6a21\u5757<\/li>\n\n\n\n<li>-DskipTests\uff1a\u8df3\u8fc7\u6d4b\u8bd5\uff0c\u63d0\u9ad8\u6784\u5efa\u901f\u5ea6<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u4e3a\u4ec0\u4e48\u4f7f\u7528 Docker \u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\uff1f \u4f20\u7edf\u90e8\u7f72\u65b9\u5f0f\u901a\u5e38\u6bd4\u8f83\u590d\u6742\uff0c\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\u65f6\u9700\u8981\u624b\u52a8\u914d\u7f6e\u8fd0\u884c\u73af\u5883\uff0c\u4f8b\u5982\uff1a \u5982\u679c\u4f7f\u7528 Do &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog-1501514697.top\/index.php?rest_route=\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog-1501514697.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog-1501514697.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog-1501514697.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog-1501514697.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=74"}],"version-history":[{"count":13,"href":"https:\/\/blog-1501514697.top\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":126,"href":"https:\/\/blog-1501514697.top\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions\/126"}],"wp:attachment":[{"href":"https:\/\/blog-1501514697.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog-1501514697.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog-1501514697.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}