spring-boot构建docker镜像上传仓库
创建一个简单spring-boot-web项目
<?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
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设置,只在本地可用
<settings>
...
<servers>
...
<server>
<id>MY_REGISTRY</id>
<username>MY_USERNAME</username>
<password>{MY_SECRET}</password>
</server>
</servers>
</settings>
标签:仓库,spring,boot,镜像,docker,com
From: https://www.cnblogs.com/lhns/p/16963077.html