1.修改docker配置文件,打開2375端口
1
2
3
4
5
6
7
8
9
10
11
|
[root @s162 docker]# vim /usr/lib/systemd/system/docker.service #查找 execstart,在末尾添加 #后面加上-h tcp: //0.0.0.0:2375 [root @s162 docker]# systemctl daemon-reload [root @s162 docker]# systemctl start docker ## 查看 2375 端口是否啟用 [root @s162 docker]# lsof -i: 2375 command pid user fd type device size/off node name dockerd 27021 root 5u ipv6 352598799 0t0 tcp *: 2375 (listen) |
2. idea安裝配置docker插件
2.1. idea-plugins市場安裝docker插件
略…
2.2. 配置docker
3.springboot項目部署到docker服務器
3.1. 編寫docker/dockerfile
3.2.maven添加docker-maven-plugin插件
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
|
<plugin> <groupid>com.spotify</groupid> <artifactid>docker-maven-plugin</artifactid> <version> 1.0 . 0 </version> <configuration> <!--指定生成的鏡像名,如果不指定tag,默認會使用latest--> <imagename>jhs/${project.artifactid}:${project.version}</imagename> <!--添加額外的指定標簽, 非必須--> <!-- <imagetags> <imagetag>${project.version}</imagetag> </imagetags> --> <!-- 指定 dockerfile 路徑 :項目根路徑下--> <dockerdirectory>${project.basedir}/docker</dockerdirectory> <!--指定遠程 docker api地址--> <dockerhost>http: //192.168.129.162:2375</dockerhost> <!-- copy資源 --> <resources> <resource> <targetpath>/</targetpath> <directory>${project.build.directory}</directory> <include>${project.build.finalname}.jar</include> </resource> </resources> <!--docker build dockerfile時:設置鏡像創建時的變量 --> <buildargs> <jar_file>target/${project.build.finalname}.jar</jar_file> </buildargs> </configuration> </plugin> |
3.3. docker:build
使用命令$ mvn clean package docker:build -dmaven.test.skip=true
構建鏡像,在docker服務器上查看鏡像是否上傳成功:
3.4 docker:tag
docker命令行格式為:
#docker tag <imageid or imagename> <nexus-hostname>:<repository-port>/<image>:<tag>
插件配置
<configuration>
補充配置:
1
2
3
4
5
|
<configuration> <image>jhs/${project.artifactid}:${project.version}</image> <!-- docker tag 打標簽--> <newname> 192.168 . 129.160 : 5000 /${project.artifactid}:${project.version}</newname> </configuration> |
為鏡像打上tag標簽,為后續的push做準備:mvn clean docker:tag -dmaven.test.skip=true -dskipdockerbuild
3.5 docker:push
插件配置
<configuration>
補充配置:
1
2
3
4
5
6
7
8
9
|
<configuration> <!-- docker push 推送到遠程鏡像倉庫--> <!-- serverid: 為在maven setting.xml配置的server信息id--> <serverid>nexus-docker-registry</serverid> <registryurl> 192.168 . 129.160 : 5000 </registryurl> <!-- 打上tag的新鏡像 push 到nexus--> <imagename> 192.168 . 129.160 : 5000 /${project.artifactid}</imagename> </configuration> |
將上文打上tag標簽的鏡像,推送到私服nexus:mvn clean docker:push -dmaven.test.skip=true -dskipdockerbuild -dskipdockertag
3.6 docker插件參數
-
-dskipdockerbuild
to skip image build -
-dskipdockertag
to skip image tag -
-dskipdockerpush
to skip image push -
-dskipdocker
to skip any docker goals
3.7 綁定命令到maven phases
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
|
<executions> <execution> <id>build-image</id> <phase> package </phase> <goals> <goal>build</goal> </goals> </execution> <execution> <id>tag-image</id> <phase> package </phase> <goals> <goal>tag</goal> </goals> <configuration> <image>jhs/${project.artifactid}:${project.version}</image> <newname> 192.168 . 129.160 : 5000 /${project.artifactid}:${project.version}</newname> </configuration> </execution> <execution> <id>push-image</id> <phase>deploy</phase> <goals> <goal>push</goal> </goals> <configuration> <!-- docker push 推送到遠程鏡像倉庫--> <!-- serverid: 為在maven setting.xml配置的server信息id--> <serverid>nexus-docker-registry</serverid> <registryurl> 192.168 . 129.160 : 5000 </registryurl> <imagename> 192.168 . 129.160 : 5000 /${project.artifactid}</imagename> </configuration> </execution> </executions> |
3.8 最佳實踐
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
73
74
75
76
77
78
79
80
81
82
83
84
|
<properties> <docker.host>http: //192.168.129.162:2375</docker.host> <docker.registry.url> 192.168 . 129.160 : 5000 </docker.registry.url> </properties> <build> <plugins> <plugin> <groupid>com.spotify</groupid> <artifactid>docker-maven-plugin</artifactid> <version> 1.0 . 0 </version> <configuration> <imagename>dic/${project.artifactid}:${project.version}</imagename> <!--添加額外的指定標簽(可配置多個), 若果沒做指定,則為latest--> <!-- <imagetags> <imagetag>${project.version}</imagetag> </imagetags> --> <!-- 指定 dockerfile 路徑 :項目根路徑下--> <dockerdirectory>${project.basedir}/docker</dockerdirectory> <!--指定遠程 docker api地址--> <dockerhost>${docker.host}</dockerhost> <!-- copy資源 --> <resources> <resource> <targetpath>/</targetpath> <directory>${project.build.directory}</directory> <include>${project.build.finalname}.jar</include> </resource> </resources> <!--docker build dockerfile時:設置鏡像創建時的變量 --> <buildargs> <jar_file>target/${project.build.finalname}.jar</jar_file> </buildargs> </configuration> <executions> <execution> <id>build-image</id> <phase> package </phase> <goals> <goal>build</goal> </goals> </execution> <execution> <id>tag-image</id> <phase> package </phase> <goals> <goal>tag</goal> </goals> <configuration> <image>dic/${project.artifactid}:${project.version}</image> <newname>${docker.registry.url}/${project.artifactid}:${project.version}</newname> </configuration> </execution> <execution> <id>push-image</id> <phase>deploy</phase> <goals> <goal>push</goal> </goals> <configuration> <!-- docker push 推送到遠程鏡像倉庫--> <!-- serverid: 為在maven setting.xml配置的server信息id--> <serverid>nexus-docker-registry</serverid> <registryurl>${docker.registry.url}</registryurl> <imagename>${docker.registry.url}/${project.artifactid}</imagename> </configuration> </execution> </executions> </plugin> </plugins> </build> |
4.docker私服倉庫harbor安裝的步驟詳解(補充)
http://m.ythuaji.com.cn/article/151025.html
到此這篇關于idea連接docker實現一鍵部署的文章就介紹到這了,更多相關idea連接docker一鍵部署內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/it_freshman/article/details/109201610