小知识:在Idea中使用Docker部署SpringBoot项目的详细步骤

前言

项目需要:

安装Dockeridea中安装docker插件,并配置docker一个SpringBoot项目创建Dockerfile

一、下载、安装、配置Docker下载Docker

下载地址:官网下载 Docker

安装

一直下一步就行

配置路径:Settings–General 勾选 Expose daemon on tcp://localhost:2375 without TLS

%小知识:在Idea中使用Docker部署SpringBoot项目的详细步骤-猿站网-插图

设置镜像,提高下载镜像的速度https://xaiqlt1z.mirror.aliyuncs.com

%小知识:在Idea中使用Docker部署SpringBoot项目的详细步骤-1猿站网-插图

测试是否安装成功

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 安装

%小知识:在Idea中使用Docker部署SpringBoot项目的详细步骤-2猿站网-插图

2.配置Docker服务

file – 搜索docker – 选择Docker – 右侧添加一个Docker

Connection successful 显示,表示 Docker链接成功

%小知识:在Idea中使用Docker部署SpringBoot项目的详细步骤-3猿站网-插图

三、创建SpringBoot项目,修改pom.xmlspringMVC 项目,访问 localhost:8080/hello 显示 hello 字符串

?
1
2
3
4
5
@RequestMapping(“/hello”)
@ResponseBody
public String hello () {
return “hello”;
}

1.配置pom.xml 文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<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打包后复制进来的。

%小知识:在Idea中使用Docker部署SpringBoot项目的详细步骤-4猿站网-插图

Dockerfile 文件内容:

?
1
2
3
4
5
6
7
8
9
10
11
12
# 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配置

%小知识:在Idea中使用Docker部署SpringBoot项目的详细步骤-5猿站网-插图

运行

%小知识:在Idea中使用Docker部署SpringBoot项目的详细步骤-6猿站网-插图

运行成功

%小知识:在Idea中使用Docker部署SpringBoot项目的详细步骤-7猿站网-插图

测试

使用docker 检查容器是否启动:

%小知识:在Idea中使用Docker部署SpringBoot项目的详细步骤-8猿站网-插图

测试项目是否启动:

%小知识:在Idea中使用Docker部署SpringBoot项目的详细步骤-9猿站网-插图

总结

今天学了下Docker容器,基本的命令学会了,但是一直没弄懂怎么使用。借此机会就花费时间进行学习。目前只是会用,后面会补上步骤详细描述。

到此这篇关于在Idea中使用Docker部署SpringBoot项目的文章就介绍到这了,更多相关Docker部署SpringBoot项目内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/qq_42428264/article/details/108504312

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:docker 安装solr8.6.2 配置中文分词器的方法

2023-3-27 17:14:09

建站知识

小知识:DockerHub 镜像仓库的使用详解

2023-3-27 17:36:42

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索