{"id":1932,"date":"2023-04-01T09:55:16","date_gmt":"2023-04-01T01:55:16","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1932"},"modified":"2023-04-22T08:47:33","modified_gmt":"2023-04-22T00:47:33","slug":"docker-and-spring-boot-integration-docker-aven-plugin-usage","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/04\/01\/docker-and-spring-boot-integration-docker-aven-plugin-usage\/","title":{"rendered":"Docker\u4e0eSpring Boot\u7684\u96c6\u6210\uff1adocker-maven-plugin\u4f7f\u7528"},"content":{"rendered":"<p>\u4f7f\u7528Spring Boot\u7f16\u5199\u4e86\u4e00\u4e2a\u5fae\u670d\u52a1\u540e\uff0c\u5982\u4f55\u5c06\u6784\u5efa\u5e94\u7528\u5e76\u6253\u5305\u6210<code>Docker<\/code>\u955c\u50cf\uff0c\u63a8\u9001\u5230<code>Docker<\/code>\u4ed3\u5e93\uff0c\u4ee5\u4f9b\u6d4b\u8bd5\u73af\u5883\u6d4b\u8bd5\u3002<\/p>\n<p><code>docker-maven-plugin<\/code>\u63d2\u4ef6\u53ef\u4ee5\u5b8c\u6210\u8fd9\u9879\u4efb\u52a1\uff0cGithub\u5730\u5740\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/spotify\/docker-maven-plugin\">https:\/\/github.com\/spotify\/docker-maven-plugin<\/a><\/p>\n<p>\u8be5\u63d2\u4ef6\u662f\u57fa\u4e8eMaven\u63d2\u4ef6\uff0c\u7528\u6765\u6784\u5efa<code>Docker<\/code>\u955c\u50cf\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5728\u7cfb\u7edf\u4e2d\u914d\u7f6e<code>Dockerfile<\/code>\u7684\u65b9\u5f0f\u6784\u5efa\u955c\u50cf\u3002<\/p>\n<p><!-- more --><\/p>\n<h2>\u76ee\u7684<\/h2>\n<p>\u53ef\u4ee5\u4f7f\u7528\u8be5\u63d2\u4ef6\u5728Maven\u9879\u76ee\u4e2d\u521b\u5efa\u4e00\u4e2a<code>Docker<\/code>\u955c\u50cf\uff0c\u6bd4\u65b9\u8bf4\uff0c<code>build<\/code>\u8fc7\u7a0b\u53ef\u4ee5\u4e3aJava\u670d\u52a1\u8f93\u51fa\u4e00\u4e2a\u53ef\u4ee5\u8fd0\u884c\u8be5\u670d\u52a1\u7684Docker\u955c\u50cf\u3002<\/p>\n<h2>\u6b65\u9aa4<\/h2>\n<p><code>Dockerfile<\/code>\u63d0\u4f9b\u4e86\u4e24\u79cd\u914d\u7f6e\u65b9\u5f0f\uff0c\u4e00\u79cd\u662f\u901a\u8fc7<code>Dockerfile<\/code>\u6587\u4ef6\uff0c\u4e00\u79cd\u662f\u76f4\u63a5\u5728<code>pom.xml<\/code>\u914d\u7f6e\u3002<\/p>\n<p>\u53ef\u4ee5\u76f4\u63a5\u5728<code>pom.xml<\/code>\u6587\u4ef6\u4e2d\u6307\u5b9a<code>base image<\/code>, <code>entry point<\/code>, <code>cmd<\/code>, <code>maintainer<\/code>\u548c<code>files<\/code>\uff0c\u800c\u4e0d\u7528\u901a\u8fc7<code>Dockerfile<\/code>\u7684\u65b9\u5f0f\u3002<\/p>\n<p>\u5f53\u7136\u901a\u8fc7<code>pom.xml<\/code>\u6587\u4ef6\u7684\u65b9\u5f0f\u652f\u6301\u4e00\u4e9b\u7b80\u5355\u7684\u547d\u4ee4\uff0c\u5982\u679c\u4f60\u9700\u8981<code>volumn<\/code>\u547d\u4ee4\uff08\u6216\u8005\u5176\u4ed6<code>pom.xml<\/code>\u4e0d\u652f\u6301\u4f7f\u7528\u7684\u547d\u4ee4\uff09\uff0c\u8fd8\u662f\u9700\u8981\u901a\u8fc7\u5c06\u547d\u4ee4\u5199\u5165<code>Dockerfile<\/code>\uff0c\u5e76\u901a\u8fc7\u5728<code>pom.xml<\/code>\u4e2d\u914d\u7f6e<code>dockerDirectory<\/code>\u6765\u5f15\u5165\u8be5<code>Dockerfile<\/code><\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8be5\u63d2\u4ef6\u901a\u8fc7\u8bbf\u95ee<code>localhost:2375<\/code>\u6765\u8fde\u63a5\u672c\u5730<code>Docker<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>DOCKER_HOST<\/code>\u73af\u5883\u53d8\u91cf\u6765\u8fde\u63a5<code>Docker<\/code><\/p>\n<pre><code>DOCKER_HOST=tcp:\/\/&lt;host&gt;:2375<\/code><\/pre>\n<h3>\u5728pom\u4e2d\u58f0\u660e\u6784\u5efa\u4fe1\u606f<\/h3>\n<p>\u4e0b\u9762\u7684\u4ee3\u7801\u793a\u4f8b\u662f\u521b\u5efa\u4e86\u540d\u4e3a<code>example<\/code>\u7684\u65b0\u955c\u50cf\uff0c\u5c06\u9879\u76ee\u7f16\u8bd1\u7684j<code>ar<\/code>\u5305\u62f7\u8d1d\u5230\u955c\u50cf\u4e2d\uff0c\u5e76\u8bbe\u7f6e\u4e86\u4e00\u4e2a<code>entrypoint<\/code>\u53bb\u8fd0\u884c\u8fd9\u4e2a<code>jar<\/code>\uff0c\u5728\u4e0b\u9762\u7684\u4ee3\u7801\u4e2d\u53ef\u4ee5\u6539\u53d8<code>VERSION GOES HERE<\/code>\u6539\u53d8\u63d2\u4ef6\u7684\u7248\u672c\uff0c\u76ee\u524d\u6700\u65b0\u7684\u7248\u672c\u662f<code>1.2.2<\/code><\/p>\n<pre><code class=\"language-xml\">&lt;build&gt;\n  &lt;plugins&gt;\n    ...\n    &lt;plugin&gt;\n      &lt;groupId&gt;com.spotify&lt;\/groupId&gt;\n      &lt;artifactId&gt;docker-maven-plugin&lt;\/artifactId&gt;\n      &lt;version&gt;VERSION GOES HERE&lt;\/version&gt;\n      &lt;configuration&gt;\n        &lt;imageName&gt;example&lt;\/imageName&gt;\n        &lt;baseImage&gt;java&lt;\/baseImage&gt;\n        &lt;entryPoint&gt;[&quot;java&quot;, &quot;-jar&quot;, &quot;\/${project.build.finalName}.jar&quot;]&lt;\/entryPoint&gt;\n        &lt;!-- copy the service&#039;s jar file from target into the root directory of the image --&gt; \n        &lt;resources&gt;\n           &lt;resource&gt;\n             &lt;targetPath&gt;\/&lt;\/targetPath&gt;\n             &lt;directory&gt;${project.build.directory}&lt;\/directory&gt;\n             &lt;include&gt;${project.build.finalName}.jar&lt;\/include&gt;\n           &lt;\/resource&gt;\n        &lt;\/resources&gt;\n      &lt;\/configuration&gt;\n    &lt;\/plugin&gt;\n    ...\n  &lt;\/plugins&gt;\n&lt;\/build&gt;<\/code><\/pre>\n<p>\u53c2\u6570\u89e3\u91ca\uff1a<\/p>\n<ul>\n<li><code>imageName<\/code>: \u955c\u50cf\u7684\u540d\u79f0\uff0c\u53ef\u4ee5\u901a\u8fc7<code>${project.groupId}\/${project.artifactId}:${project.version}<\/code>\u52a8\u6001\u5236\u5b9a\u955c\u50cf\u540d\u79f0\u3002\u5f53\u7136\u4e5f\u53ef\u4ee5\u5728\u524d\u9762\u52a0\u4e0a\u955c\u50cf\u5730\u5740\uff0c\u6bd4\u5982<code>127.0.0.1:5000<\/code>\uff0c\u4ee5\u58f0\u660e\u5c06\u6784\u5efa\u597d\u7684\u955c\u50cf\u5b58\u50a8\u5728\u672c\u5730<\/li>\n<li><code>baseImage<\/code>: \u57fa\u7840\u955c\u50cf\uff0c\u8fd9\u91cc\u662f\u76f8\u5f53\u4e8e<code>Dockerfile<\/code>\u7684<code>FROM java<\/code><\/li>\n<li><code>resources<\/code>\u4e0b\u7684\u914d\u7f6e\uff1a\u6784\u5efa\u65f6\u4f1a\u751f\u6210<code>Docker<\/code>\u6587\u4ef6\u5939\uff0c\u8fd9\u91cc\u6307\u751f\u6210\u6587\u4ef6\u5939\u7684\u5185\u5bb9\u6765\u6e90\uff0c\u5305\u542b\u4e86<code>mvn clean package<\/code>\u4e4b\u540e\u7684<code>target<\/code>\u7684\u6587\u4ef6\u548c\u751f\u6210\u7684<code>jar<\/code>\u5305<\/li>\n<\/ul>\n<h3>\u4f7f\u7528Dockerfile<\/h3>\n<p>\u4e3a\u4e86\u4f7f\u7528<code>Dockerfile<\/code>\uff0c\u5fc5\u987b\u5728<code>pom.xml<\/code>\u7684\u6587\u4ef6\u4e2d\u901a\u8fc7<code>dockerDirectory<\/code>\u6765\u6307\u660e<code>Dockerfile<\/code>\u6587\u4ef6\u7684\u6240\u5728\u76ee\u5f55\u3002\u5982\u679c\u914d\u7f6e\u4e86<code>dockerDirectory<\/code>, <code>baseImage<\/code>, <code>maintainer<\/code>, <code>cmd<\/code>\u548c<code>entryPoint<\/code>\u914d\u7f6e\u5c06\u5ffd\u7565\u3002\u4e0b\u9762\u7684\u914d\u7f6e\u4f1a\u5c06<code>dockerDirectory<\/code>\u7684\u5185\u5bb9\u62f7\u8d1d\u81f3<code>${project.build.directory}\/docker<\/code>\uff0c\u4f7f\u7528<code>resouces<\/code>\u5143\u7d20\u53ef\u4ee5\u62f7\u8d1d\u5176\u4ed6\u7684\u6587\u4ef6\uff0c\u6bd4\u5982\u751f\u6210<code>jar<\/code>\u5305\u6587\u4ef6\u3002<\/p>\n<pre><code class=\"language-xml\">&lt;build&gt;\n  &lt;plugins&gt;\n    ...\n    &lt;plugin&gt;\n      &lt;groupId&gt;com.spotify&lt;\/groupId&gt;\n      &lt;artifactId&gt;docker-maven-plugin&lt;\/artifactId&gt;\n      &lt;version&gt;VERSION GOES HERE&lt;\/version&gt;\n      &lt;configuration&gt;\n        &lt;imageName&gt;example&lt;\/imageName&gt;\n        &lt;dockerDirectory&gt;docker&lt;\/dockerDirectory&gt;\n        &lt;resources&gt;\n           &lt;resource&gt;\n             &lt;targetPath&gt;\/&lt;\/targetPath&gt;\n             &lt;directory&gt;${project.build.directory}&lt;\/directory&gt;\n             &lt;include&gt;${project.build.finalName}.jar&lt;\/include&gt;\n           &lt;\/resource&gt;\n        &lt;\/resources&gt;\n      &lt;\/configuration&gt;\n    &lt;\/plugin&gt;\n    ...\n  &lt;\/plugins&gt;\n&lt;\/build&gt;<\/code><\/pre>\n<h2>\u4f7f\u7528<\/h2>\n<p>\u6309\u7167\u4e0a\u9762\u7684\u914d\u7f6e\u4e4b\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u751f\u6210\u4e00\u4e2a\u955c\u50cf<\/p>\n<pre><code>mvn clean package docker:build<\/code><\/pre>\n<p>\u5c06\u751f\u6210\u7684\u955c\u50cf\u63a8\u9001\u5230\u955c\u50cf\u6ce8\u518c\u4e2d\u5fc3\uff0c\u901a\u8fc7<code>pushImage<\/code>\u6807\u7b7e<\/p>\n<pre><code>mvn clean package docker:build -DpushImage<\/code><\/pre>\n<p>\u5982\u679c\u63a8\u9001\u5236\u5b9atags \u7684\u955c\u50cf\uff0c\u53ef\u4f7f\u7528<code>pushImageTag<\/code>\u6807\u7b7e<\/p>\n<pre><code>mvn clean package docker:build -DpushImageTag<\/code><\/pre>\n<p>\u4e3a\u4e86\u4f7f\u5f97\u4e0a\u8ff0\u7684\u547d\u4ee4\u6267\u884c\u6210\u529f\uff0c\u9700\u8981\u5728pom\u4e2d\u914d\u7f6e<code>imageTag<\/code>\uff0c\u53ef\u4ee5\u914d\u7f6e\u591a\u4e2a<code>imageTag<\/code><\/p>\n<pre><code class=\"language-xml\">&lt;build&gt;\n  &lt;plugins&gt;\n    ...\n    &lt;plugin&gt;\n      &lt;configuration&gt;\n        ...\n        &lt;imageTags&gt;\n           &lt;imageTag&gt;${project.version}&lt;\/imageTag&gt;\n           &lt;imageTag&gt;latest&lt;\/imageTag&gt;\n        &lt;\/imageTags&gt;\n      &lt;\/configuration&gt;\n    &lt;\/plugin&gt;\n    ...\n  &lt;\/plugins&gt;\n&lt;\/build&gt;<\/code><\/pre>\n<p>\u5982\u679c\u60f3\u5f3a\u5236<code>Docker<\/code>\u5728\u6bcf\u6b21\u65b0\u7684\u6784\u5efa\u4e0a\u8986\u76d6\u955c\u50cf<code>tags<\/code>\uff0c\u53ef\u914d\u7f6e<code>foreceTags<\/code><\/p>\n<pre><code class=\"language-xml\">&lt;build&gt;\n  &lt;plugins&gt;\n    ...\n    &lt;plugin&gt;\n      &lt;configuration&gt;\n        ...\n        &lt;!-- optionally overwrite tags every time image is built with docker:build --&gt;\n        &lt;forceTags&gt;true&lt;\/forceTags&gt;\n        &lt;imageTags&gt;\n           ...\n        &lt;\/imageTags&gt;\n      &lt;\/configuration&gt;\n    &lt;\/plugin&gt;\n    ...\n  &lt;\/plugins&gt;\n&lt;\/build&gt;<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u5728\u6784\u5efa\u7684\u547d\u4ee4\u884c\u4e0a\u6dfb\u52a0\u4e0a\u955c\u50cftags:<\/p>\n<pre><code>mvn ... docker:build -DpushImageTags -DdockerImageTags=latest -DdockerImageTags=another-tag<\/code><\/pre>\n<h2>\u7ed1\u5b9adocker\u547d\u4ee4\u5230maven phases<\/h2>\n<p>\u53ef\u4ee5\u5c06<code>build<\/code>,<code>tag<\/code>&amp;<code>push<\/code>\u76ee\u6807\u7ed1\u5b9a\u5230<code>maven phases<\/code>\uff0c\u8fd9\u6837\u4ec5\u4ec5\u901a\u8fc7\u8fd0\u884c<code>mvn deploy<\/code>\u547d\u4ee4\u5c31\u80fd\u5b8c\u6210\u9879\u76ee<code>build<\/code>,<code>tag<\/code>,<code>push<\/code>\u3002\u5982\u679c\u6709\u4e00\u4e2a\u591a\u6a21\u5757\u9879\u76ee\uff0c\u5f53\u901a\u8fc7\u7ed1\u5b9a\uff0c\u5728\u7236\u9879\u76ee\u8fd0\u884c<code>maven<\/code>\u547d\u4ee4\u7684\u540c\u65f6\uff0c\u5b50\u6a21\u5757\u9879\u76ee\u53ef\u4ee5\u81ea\u52a8\u6784\u5efa\u955c\u50cf<\/p>\n<pre><code class=\"language-xml\">&lt;plugin&gt;\n  &lt;groupId&gt;com.spotify&lt;\/groupId&gt;\n  &lt;artifactId&gt;docker-maven-plugin&lt;\/artifactId&gt;\n  &lt;version&gt;VERSION GOES HERE&lt;\/version&gt;\n  &lt;executions&gt;\n    &lt;execution&gt;\n      &lt;id&gt;build-image&lt;\/id&gt;\n      &lt;phase&gt;package&lt;\/phase&gt;\n      &lt;goals&gt;\n        &lt;goal&gt;build&lt;\/goal&gt;\n      &lt;\/goals&gt;\n    &lt;\/execution&gt;\n    &lt;execution&gt;\n      &lt;id&gt;tag-image&lt;\/id&gt;\n      &lt;phase&gt;package&lt;\/phase&gt;\n      &lt;goals&gt;\n        &lt;goal&gt;tag&lt;\/goal&gt;\n      &lt;\/goals&gt;\n      &lt;configuration&gt;\n        &lt;image&gt;my-image:${project.version}&lt;\/image&gt;\n        &lt;newName&gt;registry.example.com\/my-image:${project.version}&lt;\/newName&gt;\n      &lt;\/configuration&gt;\n    &lt;\/execution&gt;\n    &lt;execution&gt;\n      &lt;id&gt;push-image&lt;\/id&gt;\n      &lt;phase&gt;deploy&lt;\/phase&gt;\n      &lt;goals&gt;\n        &lt;goal&gt;push&lt;\/goal&gt;\n      &lt;\/goals&gt;\n      &lt;configuration&gt;\n        &lt;imageName&gt;registry.example.com\/my-image:${project.version}&lt;\/imageName&gt;\n      &lt;\/configuration&gt;\n    &lt;\/execution&gt;        \n  &lt;\/executions&gt;\n&lt;\/plugin&gt;<\/code><\/pre>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8df3\u8fc7<code>Docker<\/code>\u6784\u5efa\u7684\u9636\u6bb5<\/p>\n<ul>\n<li><code>-DskipDockerBuild<\/code> \u8df3\u8fc7\u955c\u50cf\u6784\u5efa<\/li>\n<li><code>-DskipDockerTag<\/code> \u8df3\u8fc7\u955c\u50cftag\u8bbe\u7f6e<\/li>\n<li><code>-DskipDockerPush<\/code> \u8df3\u8fc7\u955c\u50cf\u63a8\u9001<\/li>\n<li><code>-DskipDocker<\/code> \u8df3\u8fc7\u6240\u6709\u7684\u955c\u50cf\u6784\u5efa\u76ee\u6807<\/li>\n<\/ul>\n<p>\u5220\u9664\u4e00\u4e2a\u540d\u79f0\u4e3afoobar\u7684\u955c\u50cf\uff0c\u53ef\u4ee5\u8fd0\u884c\u5982\u4e0b\u547d\u4ee4<\/p>\n<pre><code>mvn docker:removeImage -DimageName=foobar<\/code><\/pre>\n<p>\u83b7\u53d6\u5b8c\u6210\u7684\u914d\u7f6e\u9009\u9879\u5217\u8868\uff0c\u53ef\u8fd0\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>mvn com.spotify:docker-maven-plugin:&lt;version&gt;:help -Ddetail=true<\/code><\/pre>\n<h2>\u4f7f\u7528\u79c1\u6709\u955c\u50cf\u4e2d\u5fc3<\/h2>\n<p>\u4e3a\u4e86\u5c06\u955c\u50cf\u63a8\u9001\u5230\u79c1\u6709\u7684\u955c\u50cf\u6ce8\u518c\u4e2d\u5fc3\uff0c<code>Docker<\/code>\u9700\u8981\u5728\u955c\u50cf<code>tag<\/code>\u4e4b\u524d\u7528\u6ce8\u518c\u4e2d\u5fc3\u7684\u5730\u5740\u4f5c\u4e3a\u524d\u7f00\u3002\u6bd4\u5982\u9700\u8981\u63a8\u9001<code>my-image<\/code>\u5230<code>registry.example.com<\/code>\uff0c\u90a3\u4e48\u8fd9\u4e2a\u955c\u50cf\u9700\u8981\u547d\u540d\u4e3a<code>registry.example.com\/my-image<\/code><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u5c31\u662f\u5728<code>&lt;imageName&gt;<\/code>\u4e2d\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"language-xml\">&lt;plugin&gt;\n  &lt;groupId&gt;com.spotify&lt;\/groupId&gt;\n  &lt;artifactId&gt;docker-maven-plugin&lt;\/artifactId&gt;\n  &lt;configuration&gt;\n    &lt;imageName&gt;registry.example.com\/my-image&lt;\/imageName&gt;\n    ...<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u5f53\u901a\u8fc7\u547d\u4ee4<code>docker:build -DpushImage<\/code>\u6216\u8005<code>docker:push<\/code>\u63a8\u9001\u955c\u50cf\u65f6\uff0c<code>Docker<\/code>\u5f15\u64ce\u4f1a\u5c06\u955c\u50cf\u63a8\u9001\u5230<code>registry.example.com<\/code><\/p>\n<p>\u5f53\u7136\u4e5f\u53ef\u4ee5\u5728<code>docker:build<\/code>\u547d\u4ee4\u4e2d\u901a\u8fc7<code>docker:tag -DpushImage<\/code>\u5bf9\u521b\u5efa\u7684\u955c\u50cf\u52a0\u4e0a\u79c1\u6709\u955c\u50cf\u6ce8\u518c\u4e2d\u5fc3\u7684\u5730\u5740\uff0c\u5982\u4e0d\u914d\u7f6e\uff0c\u5219\u4f1a\u63a8\u9001\u5230\u9ed8\u8ba4\u7684\u955c\u50cf\u4e2d\u5fc3\uff0c\u5373<code>Docker Hub<\/code>\uff0c\u4e5f\u53ef\u5982\u4e0b\u8fd9\u6837\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"language-xml\">&lt;plugin&gt;\n  &lt;groupId&gt;com.spotify&lt;\/groupId&gt;\n  &lt;artifactId&gt;docker-maven-plugin&lt;\/artifactId&gt;\n  &lt;configuration&gt;\n    &lt;imageName&gt;my-image&lt;\/imageName&gt;\n    ...\n  &lt;\/configuration&gt;\n  &lt;executions&gt;\n    &lt;execution&gt;\n      &lt;id&gt;build-image&lt;\/id&gt;\n      &lt;phase&gt;package&lt;\/phase&gt;\n      &lt;goals&gt;\n        &lt;goal&gt;build&lt;\/goal&gt;\n      &lt;\/goals&gt;\n    &lt;\/execution&gt;\n    &lt;execution&gt;\n      &lt;id&gt;tag-image&lt;\/id&gt;\n      &lt;phase&gt;package&lt;\/phase&gt;\n      &lt;goals&gt;\n        &lt;goal&gt;tag&lt;\/goal&gt;\n      &lt;\/goals&gt;\n      &lt;configuration&gt;\n        &lt;image&gt;my-image&lt;\/image&gt;\n        &lt;newName&gt;registry.example.com\/my-image&lt;\/newName&gt;\n      &lt;\/configuration&gt;\n    &lt;\/execution&gt;\n  &lt;\/executions&gt;\n&lt;\/plugin&gt;<\/code><\/pre>\n<h2>\u8ba4\u8bc1<\/h2>\n<p>\u652f\u6301\u4e09\u79cd\u8ba4\u8bc1\u65b9\u5f0f\uff1a<\/p>\n<h3>\u8bfb\u53d6\u672c\u5730\u914d\u7f6e\u6587\u4ef6\uff0c\u81ea\u52a8\u8ba4\u8bc1<\/h3>\n<p>\u4ece1.0.0\u7248\u672c\u4e4b\u540e\uff0c<code>docker-maven-plugin<\/code>\u63d2\u4ef6\u4f1a\u81ea\u52a8\u8bfb\u53d6\u5230<code>docker-cli<\/code>\u7684\u8ba4\u8bc1\u914d\u7f6e\uff0c\u9ed8\u8ba4\u5728<code>~\/.dockercfg<\/code>\u548c<code>~\/.docker\/config.json<\/code>\uff0c\u800c\u65e0\u9700\u989d\u5916\u7684\u914d\u7f6e<\/p>\n<h3>GCR\u8ba4\u8bc1<\/h3>\n<p>\u5982\u679c\u672c\u673a\u914d\u7f6e<code>DOCKER_GOOGLE_CREDENTIALS<\/code>\u7684\u73af\u5883\u53d8\u91cf\uff0c\u5219\u4f1a\u4f7f\u7528<code>GCR<\/code>\u8ba4\u8bc1\u3002<\/p>\n<h3>Server\u8ba4\u8bc1<\/h3>\n<p>\u4e5f\u53ef\u4ee5\u5728Maven\u7684<code>settings.xml<\/code>\u914d\u7f6e\u8ba4\u8bc1\u4fe1\u606f\uff1a<\/p>\n<pre><code class=\"language-xml\">&lt;servers&gt;\n  &lt;server&gt;\n    &lt;id&gt;docker-hub&lt;\/id&gt;\n    &lt;username&gt;foo&lt;\/username&gt;\n    &lt;password&gt;secret-password&lt;\/password&gt;\n    &lt;configuration&gt;\n      &lt;email&gt;foo@foo.bar&lt;\/email&gt;\n    &lt;\/configuration&gt;\n  &lt;\/server&gt;\n&lt;\/servers&gt;<\/code><\/pre>\n<p>\u5728<code>pom.xml<\/code>\u5219\u901a\u8fc7\u5982\u4e0b\u914d\u7f6e\u5173\u8054\u4e0a\u8ff0<code>server id<\/code><\/p>\n<pre><code class=\"language-xml\">&lt;plugin&gt;\n  &lt;plugin&gt;\n    &lt;groupId&gt;com.spotify&lt;\/groupId&gt;\n    &lt;artifactId&gt;docker-maven-plugin&lt;\/artifactId&gt;\n    &lt;version&gt;VERSION GOES HERE&lt;\/version&gt;\n    &lt;configuration&gt;\n      [...]\n      &lt;serverId&gt;docker-hub&lt;\/serverId&gt;\n      &lt;registryUrl&gt;https:\/\/index.docker.io\/v1\/&lt;\/registryUrl&gt;\n    &lt;\/configuration&gt;\n  &lt;\/plugin&gt;\n&lt;\/plugins&gt;<\/code><\/pre>\n<p>\u4ee5\u4e0a\u4e09\u79cd\u914d\u7f6e\u65b9\u5f0f\u4e2d\uff0c\u901a\u8fc7\u8bfb\u53d6\u5ba2\u6237\u7aef\u9ed8\u8ba4\u914d\u7f6e\u7684\u4f18\u5148\u7ea7\u66f4\u9ad8\u3002<\/p>\n<h3>\u5728server\u914d\u7f6e\u4e2d\u52a0\u5bc6\u5bc6\u7801<\/h3>\n<p>\u4e3a\u4e86\u4e0d\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u4e0d\u66b4\u9732\u660e\u6587\u5bc6\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528maven\u52a0\u5bc6\u529f\u80fd\u5bf9\u5bc6\u7801\u8fdb\u884c\u52a0\u5bc6\uff0c\u901a\u8fc7<code>{ }<\/code>\u65b9\u5f0f\u90fd\u8ba4\u4e3a\u662f\u88ab\u52a0\u5bc6\u7684\u5bc6\u7801<\/p>\n<pre><code class=\"language-xml\">&lt;servers&gt;\n  &lt;server&gt;\n    &lt;id&gt;docker-hub&lt;\/id&gt;\n    &lt;username&gt;foo&lt;\/username&gt;\n    &lt;password&gt;{gc4QPLrlgPwHZjAhPw8JPuGzaPitzuyjeBojwCz88j4=}&lt;\/password&gt;\n  &lt;\/server&gt;\n&lt;\/servers&gt;<\/code><\/pre>\n<blockquote>\n<p>\u6ce8\u610f\uff1a\u6784\u5efa\u7684\u955c\u50cf\u540d\u79f0\u4e0d\u8981\u542b\u6709<code>SNAPSHOT<\/code>\uff0c\u56e0\u4e3a\u955c\u50cf\u540d\u79f0\u53ea\u5141\u8bb8<code>[a-z0-9-_.]<\/code><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528Spring Boot\u7f16\u5199\u4e86\u4e00\u4e2a\u5fae\u670d\u52a1\u540e\uff0c\u5982\u4f55\u5c06\u6784\u5efa\u5e94\u7528\u5e76\u6253\u5305\u6210Docker\u955c\u50cf\uff0c\u63a8\u9001\u5230Docker\u4ed3\u5e93\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[179,41],"tags":[],"class_list":["post-1932","post","type-post","status-publish","format-standard","hentry","category-docker","category-spring-boot"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1932"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1932\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}