一.服務(wù)器安裝docker
1
|
yum install docker |
修改配置文件,打開2375端口
1
|
[root@microservice ~] # vim /usr/lib/systemd/system/docker.service |
在ExecStart=/usr/bin/dockerd-current 后面加上-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
重新加載配置文件和啟動(dòng):
1
2
|
systemctl daemon-reload systemctl start docker |
附:docker操作相關(guān)命令
systemctl命令是系統(tǒng)服務(wù)管理器指令,它是 service 和 chkconfig 兩個(gè)命令組合。
啟動(dòng)docker:systemctl start docker
停止docker:systemctl stop docker
重啟docker:systemctl restart docker
查看docker狀態(tài):systemctl status docker
開機(jī)啟動(dòng):systemctl enable docker
二、Idea安裝docker支持插件及配置
1.idea下載docker支持插件:Docker integration
(快捷鍵Crtl+shift+A 搜索Docker integration ,然后啟用,重啟idea生效)
2.IDEA Docker插件配置
File–>Settings–>Build,Execution,Deployment–>Docker–>進(jìn)行如下配置:
tcp://服務(wù)器ip地址:2375
注意: 只要下面提示Connection successfl 就表示連接成功了;
3.配置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
|
< build > < finalName >${project.artifactId}</ finalName > < plugins > < plugin > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-maven-plugin</ artifactId > < configuration > < fork >true</ fork > </ configuration > </ plugin > <!-- 跳過(guò)單元測(cè)試 --> < plugin > < groupId >org.apache.maven.plugins</ groupId > < artifactId >maven-surefire-plugin</ artifactId > < configuration > < skipTests >true</ skipTests > </ configuration > </ plugin > <!--使用docker-maven-plugin插件--> < plugin > < groupId >com.spotify</ groupId > < artifactId >docker-maven-plugin</ artifactId > < version >1.0.0</ version > <!--將插件綁定在某個(gè)phase執(zhí)行--> < executions > < execution > < id >build-image</ id > <!--用戶只需執(zhí)行mvn package ,就會(huì)自動(dòng)執(zhí)行mvn docker:build--> < phase >package</ phase > < goals > < goal >build</ goal > </ goals > </ execution > </ executions > < configuration > <!--指定生成的鏡像名--> < imageName >fred/${project.artifactId}</ imageName > <!--指定標(biāo)簽--> < imageTags > < imageTag >latest</ imageTag > </ imageTags > <!-- 指定 Dockerfile 路徑--> < dockerDirectory >src/main/docker</ dockerDirectory > <!--指定遠(yuǎn)程 docker api地址--> < dockerHost >http://服務(wù)器ip地址:2375</ dockerHost > <!-- 這里是復(fù)制 jar 包到 docker 容器指定目錄配置 --> < resources > < resource > < targetPath >/</ targetPath > <!--jar 包所在的路徑 此處配置的 即對(duì)應(yīng) target 目錄--> < directory >${project.build.directory}</ directory > <!-- 需要包含的 jar包 ,這里對(duì)應(yīng)的是 Dockerfile中添加的文件名 --> < include >${project.build.finalName}.jar</ include > </ resource > </ resources > </ configuration > </ plugin > </ plugins > </ build > |
附項(xiàng)目目錄結(jié)構(gòu):
四、根目錄下編寫Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# Dockerfile # 基于的鏡像 FROM openjdk:8-jdk-alpine VOLUME /opt/tmp ADD sg-business.jar app.jar # -Djava.security.egd=file:/dev/./urandom 可解決tomcat可能啟動(dòng)慢的問(wèn)題 # 具體可查看:https://www.cnblogs.com/mightyvincent/p/7685310.html ENTRYPOINT [ "java" , "-Djava.security.egd=file:/dev/./urandom" , "-jar" , "/app.jar" ] # 對(duì)外端口 EXPOSE 8081 |
五、點(diǎn)擊maven的package進(jìn)行構(gòu)建
構(gòu)建成功的信息
六、點(diǎn)擊最下面的docker到docker界面,雙擊docker連上服務(wù)器docker會(huì)顯示出服務(wù)器上的docker鏡像,找到剛剛生成的鏡像(圖中2),點(diǎn)擊創(chuàng)建容器
七.配置docker 容器對(duì)外暴露端口和項(xiàng)目接口端口,然后run啟動(dòng)容器
最后,設(shè)置好后,啟動(dòng)容器,啟動(dòng)成功后去阿里云查看是否啟動(dòng)成功
參考博客地址:
https://www.jianshu.com/p/186e9926600e
https://blog.lqdev.cn/2018/07/27/springboot/chapter-fourteen/
https://www.cnblogs.com/fangts/p/10299431.html
到此這篇關(guān)于idea集合docker實(shí)現(xiàn)鏡像打包一鍵部署的文章就介紹到這了,更多相關(guān)idea集合docker實(shí)現(xiàn)鏡像打包一鍵部署內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!