id: 1027c18df1824812939d8973eb64e508
parent_id: 
item_type: 1
item_id: caefd589c99c48d38506f8b22766cfc2
item_updated_time: 1764345625124
title_diff: "[{\"diffs\":[[1,\"在Docker中部署Springboot项目\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":22}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>在Docker中部署Springboot项目</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <meta name=\\\"content-class\\\" content=\\\"yinxiang.peso.superNote\\\"/>\\\r\\\n  <meta name=\\\"application-data:yinxiang.noteLayout\\\" content=\\\"{\\\"lineSpace\\\":\\\"recommend\\\",\\\"paragraphSpace\\\":\\\"recommend\\\"}\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"38935\\\"></a>\\\r\\\n<h1>在Docker中部署Springboot项目</h1>\\\r\\\n\\\r\\\n<div><span style=\\\"margin:0px;\\\"><div style=\\\"padding:8px 0px;margin:8px auto;max-width:700px;\\\"> <div><span></span></div>\\\n<p></p>\\\n<div style=\\\"--en-blockquote:true;box-sizing: border-box; padding-left: 19px; padding-top: 6px; padding-bottom: 6px; border-left: 3px solid #b4c0cc; background-position: initial initial; background-repeat: initial initial; margin-top: 6px\\\"><div>原文链接: <a href=\\\"http://mp.weixin.qq.com/s?__biz=MzA5OTc4NzIzOA==&amp;mid=2651210168&amp;idx=1&amp;sn=e3af6c2148876ffe0b699ab63d48b03c&amp;chksm=8a322addb96816d47b045fd4a1423fbc61144102315304c1d3bd0f4906f4d7d5b87bff3746c0&amp;mpshare=1&amp;scene=1&amp;srcid=0322a53JKYChYZcNCBvtvgvj&amp;sharer_shareinfo=64d1aa8113dec86b420a032fae7c47ab&amp;sharer_shareinfo_first=64d1aa8113dec86b420a032fae7c47ab#rd\\\"><span>http://mp.weixin.qq.com/s?__biz=MzA5OTc4NzIzOA==&amp;mid=2651210...</span></a></div></div>\\\n<p></p>\\\n<div><span></span></div>\\\n<div style=\\\"\\\"><div><div><h1 style=\\\"margin:0\\\"> 在Docker中部署Springboot项目 </h1><div><span style=\\\"position:relative\\\">原创</span><span><span style=\\\"position:relative\\\">小尉</span></span><span><a style=\\\"position:relative\\\"> Java基础教程 </a></span><span><em></em></span></div><div style=\\\";\\\"><p style=\\\"margin:0\\\"><span>前面我们已经分别讲过了Docker和Springboot，那么如何在Docker中部署Springboot项目呢？今天我们来看一下。</span></p><p style=\\\"margin:0\\\"><span>在 Docker 中部署 Spring Boot 项目通常包括以下几个步骤：</span></p><p style=\\\"margin:0\\\"><span><span style=\\\"font-weight: bold;\\\">1. 创建 Spring Boot 项目</span></span></p><p style=\\\"margin:0\\\"><span>确保你已经有一个 Spring Boot 项目。如果没有，可以使用 Spring Initializr 快速生成一个。</span></p><p style=\\\"margin:0\\\"><span><span style=\\\"font-weight: bold;\\\">2. 编写 Dockerfile</span></span></p><p style=\\\"margin:0\\\"><span>Dockerfile 是一个文本文件，用于定义如何构建 Docker 镜像。它包含了一系列指令，Docker 会根据这些指令自动构建镜像。Dockerfile 是 Docker 镜像构建的核心，通过它可以定制化镜像的内容、环境和行为。</span></p><p style=\\\"margin:0\\\"><span>在项目根目录下创建一个名为 Dockerfile 的文件，内容如下：</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><span># 使用官方的 OpenJDK 镜像作为基础镜像</span></span><div><span>FROM openjdk:17-jdk-alpine</span></div><div><span><span># 设置工作目录</span></span></div><div><span>WORKDIR /app</span></div><div><span><span># 将构建的 JAR 文件复制到容器中</span></span></div><div><span>COPY target/your-springboot-app.jar app.jar</span></div><div><span><span># 暴露端口（根据你的应用配置）</span></span></div><div><span>EXPOSE 8080</span></div><div><span><span># 启动 Spring Boot 应用</span></span></div><div><span>ENTRYPOINT [<span>&quot;java&quot;</span>, <span>&quot;-jar&quot;</span>, <span>&quot;app.jar&quot;</span>]</span></div></div></pre></div><p style=\\\"margin:0\\\"><span><span style=\\\"font-weight: bold;\\\">3. 构建 Spring Boot 项目</span></span></p><p style=\\\"margin:0\\\"><span>在项目根目录下运行以下命令，生成 JAR 文件：</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>./mvnw clean package</span></div></pre></div><p style=\\\"margin:0\\\"><span><span style=\\\"font-weight: bold;\\\">4. 构建 Docker 镜像</span></span></p><p style=\\\"margin:0\\\"><span>在项目根目录下运行以下命令，构建 Docker 镜像：</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><span>docker</span> build -t your-springboot-app .</span></div></pre></div><p style=\\\"margin:0\\\"><span><span style=\\\"font-weight: bold;\\\">5. 运行 Docker 容器</span></span></p><p style=\\\"margin:0\\\"><span>使用以下命令运行容器：</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><span>docker</span> run -p <span>8080</span>:<span>8080</span> your-springboot-app</span></div></pre></div><p style=\\\"margin:0\\\"><span><span style=\\\"font-weight: bold;\\\">6. 访问应用</span></span></p><p style=\\\"margin:0\\\"><span>打开浏览器，访问 http://localhost:8080，即可看到 Spring Boot 应用。</span></p><p style=\\\"margin:0\\\"><span><span style=\\\"font-weight: bold;\\\">7. 使用 Docker Compose（可选）</span></span></p><p style=\\\"margin:0\\\"><span>如果需要管理多个容器，可以使用 docker-compose.yml 文件：</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><span>version: '3'</span></span><div><span><span>services:</span></span></div><div><span>  app:</span></div><div><span>    image: your-springboot-app</span></div><div><span>    build:</span></div><div><span>      context: .</span></div><div><span>      dockerfile: Dockerfile</span></div><div><span>    ports:</span></div><div><span>      - <span>&quot;8080:8080&quot;</span></span></div></div></pre></div><p style=\\\"margin:0\\\"><span>然后运行以下命令启动服务：</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>docker-compose up</span></div></pre></div><p style=\\\"margin:0\\\"><span><span style=\\\"font-weight: bold;\\\">总结</span></span></p><p style=\\\"margin:0\\\"><span>通过以上几个步骤，你应该可以在 Docker 中成功部署 Spring Boot 项目。</span></p><p style=\\\"margin:0\\\"><span>部署过程中有任何问题，欢迎在评论区留言。</span></p></div></div></div></div></div></span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":8905}]"
metadata_diff: {"new":{"id":"caefd589c99c48d38506f8b22766cfc2","parent_id":"f67288c3a0be4374b5d532b5dcc3aabc","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764348844782,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T21:04:13.482Z
created_time: 2025-11-28T21:04:13.482Z
type_: 13