spring-boot构建docker镜像上传仓库
创建一个简单spring-boot-web项目
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
|
<? 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.3.2.RELEASE</ version > </ parent > < groupId >com.example</ groupId > < artifactId >spring-boot-docker-demo</ artifactId > < version >1.0.0</ version > < properties > < jave.version >1.8</ jave.version > </ properties > < dependencies > < dependency > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-starter-web</ artifactId > </ dependency > </ dependencies > < build > < plugins > < plugin > < groupId >com.google.cloud.tools</ groupId > < artifactId >jib-maven-plugin</ artifactId > < version >1.8.0</ version > < configuration > < from > <!-- 拉取基础镜像 --> < image >openjdk:8-jdk-alpine</ image > </ from > < to > <!-- 格式:官方docker hub->用户名/镜像名 --> <!-- 格式:阿里云容器镜像服务->registry.cn-hangzhou.aliyuncs.com/服务空间/镜像名 --> < image >registry.cn-hangzhou.aliyuncs.com/服务空间/${project.name}</ image > <!-- 镜像版本号 --> < tags > < tag >latest</ tag > < tag >${project.version}</ tag > </ tags > < auth > < username >用户名</ username > < password >密码</ password > </ auth > </ to > < container > <!-- 启动类 --> < mainClass >启动类地址</ mainClass > < useCurrentTimestamp >use</ useCurrentTimestamp > <!-- 服务暴露的端口 --> < ports > < port >8080</ port > </ ports > </ container > </ configuration > < executions > < execution > < phase >package</ phase > < goals > < goal >build</ goal > </ goals > </ execution > </ executions > </ plugin > </ plugins > </ build > </ project > |
准备工作
- 创建docker仓库镜像工程
- 配置docker hub push参数
执行
查看镜像上传仓库
思考
这时候我们发现当前仓库信息明文暴露在项目中,这时候又要怎么处理,让其提高安全性。
方案1
1
|
mvn compile com.google.cloud.tools:jib-maven-plugin:1.8.0:build -Djib.to.auth.username=user -Djib.to.auth.password=pass -Dimage=<MY IMAGE> |
方案2
使用maven设置,只在本地可用
1
2
3
4
5
6
7
8
9
10
11
|
<settings> ... <servers> ... <server> <id>MY_REGISTRY</id> <username>MY_USERNAME</username> <password>{MY_SECRET}</password> </server> </servers> </settings> |
到此这篇关于spring-boot构建docker镜像上传仓库的文章就介绍到这了,更多相关docker镜像上传仓库内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://www.cnblogs.com/lhns/p/16963077.html