在Idea中使⽤Docker部署SpringBoot项⽬的详细步骤前⾔
项⽬需要:
安装Dockeridea中安装docker插件,并配置docker⼀个SpringBoot项⽬创建Dockerfile
⼀、下载、安装、配置Docker下载Docker
下载地址:官⽹下载 Docker
安装
⼀直下⼀步就⾏
配置路径:Settings–General 勾选Expose daemon on tcp://localhost:2375 without TLS
测试是否安装成功
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:
hub.docker/
For more examples and ideas, visit:
docs.docker/get-started/
⼆、Idea 安装Docker插件
1.安装docker插件在idea中: file--Plugins--Marketplace 搜索 Docker 安装
2.配置Docker服务
file – 搜索docker – 选择Docker – 右侧添加⼀个Docker
Connection successful 显⽰,表⽰ Docker链接成功
三、创建SpringBoot项⽬,修改lspringMVC 项⽬,访问 localhost:8080/hello 显⽰ hello 字符串@RequestMapping("/hello")
@ResponseBody
public String hello () {
return "hello";
}
1.配置l ⽂件
<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>localhost:2375</dockerHost>
<resources>
spring framework<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项⽬内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。