{"id":4216,"date":"2024-11-11T10:46:20","date_gmt":"2024-11-11T02:46:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/4216\/"},"modified":"2024-11-11T10:46:20","modified_gmt":"2024-11-11T02:46:20","slug":"%e5%b0%86-java-%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e5%ae%b9%e5%99%a8%e5%8c%96","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/4216\/","title":{"rendered":"\u5c06 Java \u5e94\u7528\u7a0b\u5e8f\u5bb9\u5668\u5316"},"content":{"rendered":"<h1>\u5c06 Java \u5e94\u7528\u7a0b\u5e8f\u5bb9\u5668\u5316<\/h1>\n<h2><\/h2>\n<ul>\n<li>\u60a8\u5df2\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684 \u3002 Docker \u5b9a\u671f\u6dfb\u52a0\u65b0\u529f\u80fd\uff0c\u672c\u6307\u5357\u7684\u67d0\u4e9b\u90e8\u5206\u53ef\u80fd\u4ec5\u9002\u7528\u4e8e\u6700\u65b0\u7248\u672c\u7684 Docker Desktop\u3002<\/li>\n<\/ul>\n<ul>\n<li>\u60a8\u6709\u4e00\u4e2a \u3002\u672c\u8282\u4e2d\u7684\u793a\u4f8b\u4f7f\u7528\u57fa\u4e8e\u547d\u4ee4\u884c\u7684 Git \u5ba2\u6237\u7aef\uff0c\u4f46\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u5ba2\u6237\u7aef\u3002<\/li>\n<\/ul>\n<h2><\/h2>\n<p>\u672c\u90e8\u5206\u5c06\u5f15\u5bfc\u60a8\u5b8c\u6210\u5bb9\u5668\u5316\u548c\u8fd0\u884c Java \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<h2><\/h2>\n<p>\u5c06\u60a8\u5c06\u4f7f\u7528\u7684\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u514b\u9686\u5230\u672c\u5730\u5f00\u53d1\u8ba1\u7b97\u673a\u3002\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u514b\u9686\u5b58\u50a8\u5e93\u3002<\/p>\n<p><span> <\/span><br \/>\n<span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> git clone https:\/\/github.com\/spring-projects\/spring-petclinic.git <\/span><\/span><\/code><\/pre>\n<p>\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u662f\u4f7f\u7528 Maven \u6784\u5efa\u7684 Spring Boot \u5e94\u7528\u7a0b\u5e8f\u3002\u6709\u5173\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605<code>readme.md<\/code>\u5b58\u50a8\u5e93\u3002<\/p>\n<h2><\/h2>\n<p>\u73b0\u5728\u60a8\u5df2\u7ecf\u6709\u4e86\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u60a8\u53ef\u4ee5\u7528\u6765<code>docker init<\/code>\u521b\u5efa\u5fc5\u8981\u7684 Docker \u8d44\u4ea7\u6765\u5bb9\u5668\u5316\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u76ee\u5f55\u5185 <code>spring-petclinic<\/code>\uff0c<code>docker init<\/code>\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u547d\u4ee4\u3002 <code>docker init<\/code>\u63d0\u4f9b\u4e86\u4e00\u4e9b\u9ed8\u8ba4\u914d\u7f6e\uff0c\u4f46\u60a8\u9700\u8981\u56de\u7b54\u4e00\u4e9b\u6709\u5173\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u95ee\u9898\u3002\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u793a\u4f8b\u4e2d\u7684\u7b54\u6848\u6765\u9075\u5faa\u672c\u6307\u5357\u3002<\/p>\n<p>\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u5df2\u5305\u542b Docker \u8d44\u4ea7\u3002\u7cfb\u7edf\u5c06\u63d0\u793a\u60a8\u8986\u76d6\u73b0\u6709\u7684 Docker \u8d44\u4ea7\u3002\u8981\u7ee7\u7eed\u9605\u8bfb\u672c\u6307\u5357\uff0c\u8bf7\u9009\u62e9<code>y<\/code>\u8986\u76d6\u5b83\u4eec\u3002<\/p>\n<p><span> <\/span><br \/>\n<span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> docker init <\/span><\/span><span><span><span>Welcome to the Docker Init CLI! <\/span><\/span><\/span><span><span><span><\/span><span> <\/span><\/span><\/span><span><span><span><\/span><span>This utility will walk you through creating the following files with sensible defaults for your project: <\/span><\/span><\/span><span><span><span> - .dockerignore <\/span><\/span><\/span><span><span><span> - Dockerfile <\/span><\/span><\/span><span><span><span> - compose.yaml <\/span><\/span><\/span><span><span><span> - README.Docker.md <\/span><\/span><\/span><span><span><span><\/span><span> <\/span><\/span><\/span><span><span><span><\/span><span>Let's get started! <\/span><\/span><\/span><span><span><span><\/span><span> <\/span><\/span><\/span><span><span><span><\/span><span>WARNING: The following Docker files already exist in this directory: <\/span><\/span><\/span><span><span><span> - docker-compose.yml <\/span><\/span><\/span><span><span><span>? Do you want to overwrite them? Yes <\/span><\/span><\/span><span><span><span>? What application platform does your project use? Java <\/span><\/span><\/span><span><span><span>? What's the relative directory (with a leading .) for your app? .\/src <\/span><\/span><\/span><span><span><span>? What version of Java do you want to use? 17 <\/span><\/span><\/span><span><span><span>? What port does your server listen on? 8080 <\/span><\/span><\/span><\/code><\/pre>\n<p>\u5728\u524d\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u8bf7\u6ce8\u610f<code>WARNING<\/code>.<code>docker-compose.yaml<\/code>\u5df2\u7ecf\u5b58\u5728\uff0c\u56e0\u6b64<code>docker init<\/code>\u8986\u76d6\u8be5\u6587\u4ef6\u800c\u4e0d\u662f\u521b\u5efa\u65b0 <code>compose.yaml<\/code>\u6587\u4ef6\u3002\u8fd9\u53ef\u4ee5\u9632\u6b62\u76ee\u5f55\u4e2d\u5b58\u5728\u591a\u4e2a Compose \u6587\u4ef6\u3002\u8fd9\u4e24\u4e2a\u540d\u79f0\u90fd\u53d7\u652f\u6301\uff0c\u4f46 Compose \u66f4\u559c\u6b22\u89c4\u8303\u7684 <code>compose.yaml<\/code>.<\/p>\n<p>\u60a8\u7684\u76ee\u5f55\u4e2d\u73b0\u5728\u5e94\u8be5\u6709\u4ee5\u4e0b\u4e09\u4e2a\u65b0\u6587\u4ef6<code>spring-petclinic<\/code> \u3002<\/p>\n<ul>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<p>\u60a8\u53ef\u4ee5\u5728\u4ee3\u7801\u6216\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u6253\u5f00\u6587\u4ef6\uff0c\u7136\u540e\u9605\u8bfb\u6ce8\u91ca\u4ee5\u4e86\u89e3\u6709\u5173\u8bf4\u660e\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u6216\u8bbf\u95ee\u4e0a\u4e00\u4e2a\u5217\u8868\u4e2d\u7684\u94fe\u63a5\u3002<\/p>\n<h2><\/h2>\n<p>\u5728\u76ee\u5f55\u5185<code>spring-petclinic<\/code>\uff0c\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<p><span> <\/span><br \/>\n<span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> docker compose up --build <\/span><\/span><\/code><\/pre>\n<p>\u7b2c\u4e00\u6b21\u6784\u5efa\u5e76\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0cDocker \u4f1a\u4e0b\u8f7d\u4f9d\u8d56\u9879\u5e76\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u53ef\u80fd\u9700\u8981\u51e0\u5206\u949f\u7684\u65f6\u95f4\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u60a8\u7684\u7f51\u7edc\u8fde\u63a5\u3002<\/p>\n<p>\u67e5\u770b\u5e94\u7528\u7a0b\u5e8f \u3002\u60a8\u5e94\u8be5\u4f1a\u770b\u5230\u4e00\u4e2a\u7b80\u5355\u7684\u5ba0\u7269\u8bca\u6240\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u4e2d\uff0c\u6309<code>ctrl<\/code>+<code>c<\/code>\u505c\u6b62\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<h3><\/h3>\n<p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u9009\u9879\u6765\u8fd0\u884c\u4e0e\u7ec8\u7aef\u5206\u79bb\u7684\u5e94\u7528\u7a0b\u5e8f<code>-d<\/code> \u3002\u5728\u76ee\u5f55\u5185<code>docker-php-sample<\/code>\uff0c\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<p><span> <\/span><br \/>\n<span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> docker compose up --build -d <\/span><\/span><\/code><\/pre>\n<p>\u67e5\u770b\u5e94\u7528\u7a0b\u5e8f \u3002\u60a8\u5e94\u8be5\u4f1a\u770b\u5230\u4e00\u4e2a\u7b80\u5355\u7684\u5ba0\u7269\u8bca\u6240\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u4e2d\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u505c\u6b62\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p><span> <\/span><br \/>\n<span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> docker compose down <\/span><\/span><\/code><\/pre>\n<p>\u6709\u5173 Compose \u547d\u4ee4\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 \u3002<\/p>\n<h2><\/h2>\n<p>\u5728\u672c\u90e8\u5206\u4e2d\uff0c\u60a8\u4e86\u89e3\u4e86\u5982\u4f55\u4f7f\u7528 Docker \u5bb9\u5668\u5316\u548c\u8fd0\u884c Java \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u76f8\u5173\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li><\/li>\n<\/ul>\n<h2><\/h2>\n<p>\u5728\u4e0b\u4e00\u8282\u4e2d\uff0c\u60a8\u5c06\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 Docker \u5bb9\u5668\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c06 Java \u5e94\u7528\u7a0b\u5e8f\u5bb9\u5668\u5316 \u60a8\u5df2\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684 \u3002 Docker \u5b9a\u671f\u6dfb\u52a0\u65b0\u529f\u80fd\uff0c\u672c\u6307\u5357\u7684\u67d0\u4e9b\u90e8\u5206\u53ef\u80fd\u4ec5\u9002\u7528\u4e8e\u6700\u65b0\u7248\u672c\u7684 Docker Desktop\u3002 \u60a8\u6709\u4e00\u4e2a \u3002\u672c\u8282\u4e2d\u7684\u793a\u4f8b\u4f7f\u7528\u57fa\u4e8e\u547d\u4ee4\u884c\u7684 Git \u5ba2\u6237\u7aef\uff0c\u4f46\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u5ba2\u6237\u7aef\u3002 \u672c\u90e8\u5206\u5c06\u5f15\u5bfc\u60a8\u5b8c\u6210\u5bb9\u5668\u5316\u548c\u8fd0\u884c Java \u5e94\u7528\u7a0b\u5e8f\u3002 \u5c06\u60a8\u5c06\u4f7f\u7528\u7684\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u514b\u9686\u5230\u672c\u5730\u5f00\u53d1\u8ba1\u7b97\u673a\u3002\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u514b\u9686\u5b58\u50a8\u5e93\u3002 $ git clone https:\/\/github.com\/spring-projects\/spring-petclinic.git \u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u662f\u4f7f\u7528 Maven \u6784\u5efa\u7684 Spring Boot \u5e94\u7528\u7a0b\u5e8f\u3002\u6709\u5173\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605readme.md\u5b58\u50a8\u5e93\u3002 \u73b0\u5728\u60a8\u5df2\u7ecf\u6709\u4e86\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u60a8\u53ef\u4ee5\u7528\u6765docker init\u521b\u5efa\u5fc5\u8981\u7684 Docker \u8d44\u4ea7\u6765\u5bb9\u5668\u5316\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u76ee\u5f55\u5185 spring-petclinic\uff0cdocker init\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u547d\u4ee4\u3002 docker init\u63d0\u4f9b\u4e86\u4e00\u4e9b\u9ed8\u8ba4\u914d\u7f6e\uff0c\u4f46\u60a8\u9700\u8981\u56de\u7b54\u4e00\u4e9b\u6709\u5173\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u95ee\u9898\u3002\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u793a\u4f8b\u4e2d\u7684\u7b54\u6848\u6765\u9075\u5faa\u672c\u6307\u5357\u3002 \u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u5df2\u5305\u542b Docker \u8d44\u4ea7\u3002\u7cfb\u7edf\u5c06\u63d0\u793a\u60a8\u8986\u76d6\u73b0\u6709\u7684 Docker \u8d44\u4ea7\u3002\u8981\u7ee7\u7eed\u9605\u8bfb\u672c\u6307\u5357\uff0c\u8bf7\u9009\u62e9y\u8986\u76d6\u5b83\u4eec\u3002 $ docker init Welcome to the Docker Init CLI! This utility will walk you through [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-4216","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=4216"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4216\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=4216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=4216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=4216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}