- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章IDEA中进行Docker项目部署的实现步骤由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
现在大部分项目已经开始部署在docker上面了,可是部署环节还是有点麻烦,所以本文想讲解一下如何使用idea一键部署。
docker配置 。
修改配置文件 。
1
2
3
4
5
6
7
8
9
|
打开docker的配置文件:
vim
/usr/lib/systemd/system/docker
.service
将下面这行注释掉:
# execstart=/usr/bin/dockerd -h fd:// --containerd=/run/containerd/containerd.sock
新写一行:
execstart=
/usr/bin/dockerd
-h tcp:
//0
.0.0.0:2375 -h unix:
///var/run/docker
.sock
重新加载配置文件和启动:
systemctl daemon-reload
systemctl start docker
|
如下图所示:
idea配置docker 。
安装docker插件 。
配置docker信息 。
在设置中进行docker配置,需要配置api url,下面出现connection successful即可:
项目搭建 。
新建一个springboot项目 。
通过idea搭建项目,什么都不需要选择,一直下一步就可以了:
修改pom文件 。
最主要的就是两点:
1.properties标签中添加 。
1
|
<
docker.image.prefix
>demo</
docker.image.prefix
>
|
2.添加新的plugin标签 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<
plugin
>
<
groupid
>com.spotify</
groupid
>
<
artifactid
>docker-maven-plugin</
artifactid
>
<
version
>1.2.1</
version
>
<
configuration
>
<
imagename
>${docker.image.prefix}/${project.artifactid}</
imagename
>
<
dockerdirectory
></
dockerdirectory
>
<
resources
>
<
resource
>
<
targetpath
>/</
targetpath
>
<
directory
>${project.build.directory}</
directory
>
<
include
>${project.build.finalname}.jar</
include
>
</
resource
>
</
resources
>
</
configuration
>
</
plugin
>
|
下面是完整的pom文件:
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
project
xmlns
=
"http://maven.apache.org/pom/4.0.0"
xmlns:xsi
=
"http://www.w3.org/2001/xmlschema-instance"
xsi:schemalocation
=
"http://maven.apache.org/pom/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<
modelversion
>4.0.0</
modelversion
>
<
parent
>
<
groupid
>org.springframework.boot</
groupid
>
<
artifactid
>spring-boot-starter-parent</
artifactid
>
<
version
>2.2.1.release</
version
>
<
relativepath
/>
<!-- lookup parent from repository -->
</
parent
>
<
groupid
>com.example</
groupid
>
<
artifactid
>demo</
artifactid
>
<
version
>0.0.1</
version
>
<
name
>demo</
name
>
<
description
>demo project for spring boot</
description
>
<
properties
>
<
java.version
>1.8</
java.version
>
<
docker.image.prefix
>demo</
docker.image.prefix
>
</
properties
>
<
dependencies
>
<
dependency
>
<
groupid
>org.springframework.boot</
groupid
>
<
artifactid
>spring-boot-starter</
artifactid
>
</
dependency
>
<
dependency
>
<
groupid
>org.springframework.boot</
groupid
>
<
artifactid
>spring-boot-starter-web</
artifactid
>
</
dependency
>
<
dependency
>
<
groupid
>org.springframework.boot</
groupid
>
<
artifactid
>spring-boot-starter-test</
artifactid
>
<
scope
>test</
scope
>
<
exclusions
>
<
exclusion
>
<
groupid
>org.junit.vintage</
groupid
>
<
artifactid
>junit-vintage-engine</
artifactid
>
</
exclusion
>
</
exclusions
>
</
dependency
>
</
dependencies
>
<
build
>
<
plugins
>
<
plugin
>
<
groupid
>org.springframework.boot</
groupid
>
<
artifactid
>spring-boot-maven-plugin</
artifactid
>
</
plugin
>
<
plugin
>
<
groupid
>com.spotify</
groupid
>
<
artifactid
>docker-maven-plugin</
artifactid
>
<
version
>1.2.1</
version
>
<
configuration
>
<
imagename
>${docker.image.prefix}/${project.artifactid}</
imagename
>
<
dockerdirectory
></
dockerdirectory
>
<
resources
>
<
resource
>
<
targetpath
>/</
targetpath
>
<
directory
>${project.build.directory}</
directory
>
<
include
>${project.build.finalname}.jar</
include
>
</
resource
>
</
resources
>
</
configuration
>
</
plugin
>
</
plugins
>
</
build
>
</
project
>
|
新建dockerfile文件 。
需要在根目录下新建dockerfile文件 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#指定基础镜像,在其上进行定制
from java:8
#维护者信息
maintainer zhouzhaodong <xiuaiba@163.com>
#这里的 /tmp 目录就会在运行时自动挂载为匿名卷,任何向 /tmp 中写入的信息都不会记录进容器存储层
volume
/tmp
#复制上下文目录下的target/demo-1.0.0.jar 到容器里
copy target
/demo-0
.0.1.jar demo-1.0.0.jar
#bash方式执行,使demo-1.0.0.jar可访问
#run新建立一层,在其上执行这些命令,执行结束后, commit 这一层的修改,构成新的镜像。
run
bash
-c
"touch /demo-1.0.0.jar"
#声明运行时容器提供服务端口,这只是一个声明,在运行时并不会因为这个声明应用就会开启这个端口的服务
expose 8080
#指定容器启动程序及参数 <entrypoint> "<cmd>"
entrypoint [
"java"
,
"-jar"
,
"demo-1.0.0.jar"
]
|
新建controller文件 。
别忘记在pom文件中添加web依赖.
1
2
3
4
5
6
7
8
9
|
@restcontroller
public
class
testcontroller {
@requestmapping
(
"/"
)
public
string test(){
return
"test docker"
;
}
}
|
maven打包 。
install打包:
生成jar包:
新建配置 。
新建dockerfile运行配置:
添加如下信息,找到自己写的dockerfile文件,配置端口映射:
生成docker镜像并运行 。
直接运行刚才新建的dockerfile运行配置即可:
运行成功后log窗口会出现项目运行的信息:
访问对应的地址即可显示我们输入的信息:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:https://segmentfault.com/a/1190000021052749 。
最后此篇关于IDEA中进行Docker项目部署的实现步骤的文章就讲到这里了,如果你想了解更多关于IDEA中进行Docker项目部署的实现步骤的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我有以下内容: sourceSets { integrationTest { java.srcDir file('.') } } dependencies {
有没有一种简单的方法可以在 IntelliJ IDEA 中为非 Java 项目配置完全自定义的构建过程?基本上,我只需要运行一个自定义的 shell 命令,而不是任何更智能的构建过程。 最佳答案 尝试
有没有办法用快捷方式将变量拉到 try-catch 块之外?例如: 来自: try{ AbstractList t1 = new ArrayList(); } catch (Exception
当我启动 IntelliJ IDEA 时,会出现该消息,但我找不到有关该功能的任何信息以及它如何帮助我。 Enable smart keyboard internalization for IDEA.
这个问题在这里已经有了答案: 10年前关闭。 Possible Duplicate: Intellij Idea 9, what folders to check into (or not check
我的目录中有一个名为 protected.keys 的新资源文件。创建它时,我要求 IntelliJ 将其视为 properties。 相反,我想将其更改为 text 请问我该怎么做? 最佳答案 您可
我的目录中有一个名为 protected.keys 的新资源文件。创建它时,我要求 IntelliJ 将其视为 properties。 相反,我想将其更改为 text 请问我该怎么做? 最佳答案 您可
我有一个带有两个 child 的 Gradle 的 Kotlin 项目。每当我尝试在 IDEA 中打开它时,其中一个 child 会在树中显示两次。 在树中,您可以在顶层看到两个项目,grpc 和 g
我不确定这是更多 Gradle 还是 Intellij Idea 问题。在 projet 中,我使用 gradle import(从 Idea 中的 Gradle 外部模型导入)导入到 Idea,我的
我在 Gradle 多项目配置上使用 idea 插件来生成 Intellij 配置文件。目前,构建在 Gradle 中运行良好,但由于缺少 JPA 元模型源文件,它在 IDE 上给了我错误。 我的问题
我在 事件日志 中得到信息 08:54:02 无法导入 maven 项目:查看日志了解详情 在 Intellij IDEA 15CE 中哪里可以找到这个日志文件? 最佳答案 您可以从 Help 访问事
我的 IntelliJ IDEA 有问题。当我打开 Find in Path 时,它显示在第二个监视器的模态窗口中,而不是像以前一样显示在主窗口内的窗口中。无法将该窗口移动到主监视器。我不记得我是否更
我按照以下 session 中的说明安装了 IntelliJ IDEA。 Install IntelliJ IDEA as a snap package on Linux sudo snap inst
可以在 IntelliJ IDEA 中配置多种类型的终端,例如cmd、powershell、git bash 等? 最佳答案 目前不可能,但有一个相关的功能请求:https://youtrack.je
我下载了 intellij 社区版。DropToFrame 是不是只有终极版才有? 任何其他插件将此添加到 intellij 社区版 谢谢 最佳答案 Drop Frame 已重命名为 Reset Fr
每次写“todo”评论时,我都面临着写我的 vcs 当前分支名称的问题。 最近我了解了 Intellij 的“Live Templates”,使用起来非常舒服。我尝试将它应用于我的问题,但没有模板可以
有一天,我运行了一些大的东西,弹出一个窗口说堆内存内存不足,我在那个窗口中将其设置为2014M,然后单击继续。一切都很好。 但我不喜欢数字 2014,我想要它 2048。因此,我更改了 idea64.
当我尝试编辑和保存 javascript 文件时,IntelliJ 使它不可能: 无法保存 C:\Users\dev\joo-web\trunk\joo-admin-web\src\main\weba
我在一个相当大的项目中升级了 IntelliJ Idea 中的语言级别,我想找到所有已弃用的方法用法 - 我寻找所有出现的罢工。 我为 PhpStorm 找到了一个类似的问题建议的方法在哪里: 代码
我必须对使用匈牙利表示法的遗留代码(以及系统匈牙利语)进行一些维护。不幸的是,将它全部从代码库中清除对我来说是不切实际的。 本地 Eclipse 用户声称可以配置 Eclipse 以便自动生成的访问器
我是一名优秀的程序员,十分优秀!