springboot docker教程(在Idea中使用Docker部署SpringBoot项目的详细步骤)
springboot docker教程
在Idea中使用Docker部署SpringBoot项目的详细步骤前言
项目需要:
安装Dockeridea中安装docker插件,并配置docker一个SpringBoot项目创建Dockerfile
一、下载、安装、配置Docker下载Docker
下载地址:官网下载 Docker
安装
一直下一步就行
配置路径:Settings–General 勾选 Expose daemon on tcp://localhost:2375 without TLS
设置镜像,提高下载镜像的速度https://xaiqlt1z.mirror.aliyuncs.com
测试是否安装成功
C:\Users\msi>docker -v Docker version 19.03.12, build 48a66213fe C:\Users\msi> docker run hello-world Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
二、Idea 安装Docker插件
1.安装docker插件在idea中: file--Plugins--Marketplace 搜索 Docker 安装
2.配置Docker服务
file – 搜索docker – 选择Docker – 右侧添加一个Docker
Connection successful 显示,表示 Docker链接成功
三、创建SpringBoot项目,修改pom.xmlspringMVC 项目,访问 localhost:8080/hello 显示 hello 字符串
@RequestMapping("/hello") @ResponseBody public String hello () { return "hello"; }
1.配置pom.xml 文件
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version> 1.2.1</version> <executions> <execution> <id>build-image</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> <configuration> <imageName>${project.artifactId}</imageName> <imageTags> <imageTag>latest</imageTag> </imageTags> <dockerDirectory>${project.basedir}</dockerDirectory> <dockerHost>http://localhost:2375</dockerHost> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}</include> </resource> </resources> </configuration> </plugin> </plugins> </build>
2.创建Docker 文件
在main文件夹下创建一个docker文件夹,并在里面创建一个Dockerfile文件。xxxxx.jar 是使用maven打包后复制进来的。
Dockerfile 文件内容:
# From java image, version : 8 FROM java:8 # 挂载app目录 VOLUME /app # COPY or ADD to image COPY demo-0.0.1-SNAPSHOT.jar app.jar RUN bash -c "touch /app.jar" EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"]
maven打包,将其target目录下的jar包复制进docker目录下。
配置Dockerfile配置
运行
运行成功
测试
使用docker 检查容器是否启动:
测试项目是否启动:
总结
今天学了下Docker容器,基本的命令学会了,但是一直没弄懂怎么使用。借此机会就花费时间进行学习。目前只是会用,后面会补上步骤详细描述。
到此这篇关于在Idea中使用Docker部署SpringBoot项目的文章就介绍到这了,更多相关Docker部署SpringBoot项目内容请搜索开心学习网以前的文章或继续浏览下面的相关文章希望大家以后多多支持开心学习网!
- 2022-01-26 01:41:54
- docker如何改tomcat(docker安装Tomcat 404问题的解决方案)
- docker 容器怎么访问宿主机网络(Docker绑定固定IP/跨主机容器互访操作)
- springboot与docker(详解SpringBoot项目docker环境运行时无限重启问题)
- 用docker搭建在线开发环境(Docker环境搭建的简单方法)
- docker镜像实例(Docker的镜像制作与整套项目一键打包部署的实现)
- netcoredocker视频教程(Docker安装部署Net Core实现过程解析)
- docker 容器运行的数据在哪里(docker容器的几种存储详解)
- dockerspringboot一键部署(docker-compose镜像发布springboot项目的流程分析)
- docker容器的使用过程(详解docker容器的层的概念)
- dockerfile配置参数(dockerfile中ENTRYPOINT与CMD的结合使用及区别)
- docker1.12.5容器假死(解决docker run后容器出现Exited 0情况的问题)
- docker harbor 配置中央仓库(Docker Gitlab+Jenkins+Harbor构建持久化平台操作)
- docker查看某个容器状态(docker 移除掉运行不正常的container操作)
- docker暴露端口无法访问(完美解决Windows10下无法对docker容器进行端口访问的操作)
- dockerfile深度解析(Dockerfile文本文件使用方法实例解析)
- 没钱可以快乐吗(没钱也能快乐吗)
- 快乐是什么(快乐就是)
- 东南亚有哪个国家(东南亚有哪个国家最发达)
- 东南亚安全吗(好不好挣钱)
- 潘长江小品《照亮全家福》台词剧本完整版(潘长江小品照亮全家福台词剧本完整版)
- 一窗通办政务服务小品剧本(一窗通办政务服务小品剧本)
热门推荐
- laravel框架怎么定时任务(laravel Model 执行事务的实现)
- dedecms二次开发教程(dedecms二次开发时使用{dede:arclist},{dede:list}获取附加表字段内容)
- docker-compose查看服务状态(Docker+DockerCompose封装web应用的方法步骤)
- 如何提升代码质量
- 宝塔面板密码忘了怎么找回(忘记宝塔面板登录地址安全入口后缀找回方法)
- python代码计算一个月多少天(Python计算时间间隔精确到微妙的代码实例)
- sql如何查询进阶(Superset实现动态SQL查询功能)
- python处理tcp包(Python3使用TCP编写一个简易的文件下载器功能)
- mysql快速创建索引(MySQL创建高性能索引的全步骤)
- php实用工具(php常用的工具开发整理)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9