我正在尝试使用Google JIB maven 插件构建我的 docker 映像并将其部署到私有注册表。但是,它因访问私有注册表的问题而失败。
我已经在我的Windows 10机器上安装了Docker Desktop v19.03.1 。接下来我尝试使用 Google JIB Maven 插件来构建我的 Spring Boot 应用程序,然后推送构建在私有注册表上的图像。
我已将 CERT 添加到 Windows 受信任的 CERTS 中的“example.registry.com”。我能够使用 docker 命令登录到私有注册表来验证这一点,如下所示:-
泊坞窗登录 example.registry.com
此命令返回身份验证成功,这意味着我添加的 CERT 已被接受。
并且在登录到私有注册表之后,我可以使用 docker 命令行成功地PULL和PUSH图像到“example.registry.com”。
下面是我的POM.xml文件。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.5.1</version>
<configuration>
<to>
<image>example.registry.com/inventory-service-docker:1.0</image>
<auth>
<username>plaintextusernameforRegistry</username>
<password>plaintestpasswordforRegistry</password>
</auth>
</to>
<from>
<image>openjdk:8</image>
</from>
<container>
<ports>
<port>8089</port>
</ports>
</container>
<allowInsecureRegistries>true</allowInsecureRegistries> <!-- this is commented on the first run.-->
</configuration>
</plugin>
当我从带有 pom.xml 文件的目录中的控制台运行“mvn compile jib:build”命令时,它确实开始了处理,但是在稍后阶段失败并出现以下错误:-
[错误] 无法在项目 inventory-service-docker 上执行目标 com.google.cloud.tools:jib-maven-plugin:1.5.1:build (default-cli): Build image failed, 也许你应该使用一个注册表支持 HTTPS 或设置配置参数“allowInsecureRegistries”:无法在https://example.registry.com/v2/inventory-service-docker/blobs/sha256:9cc2ad81d40d54dcae7fa5e8e17d9c34e8bba3b7c2cc7e26fb22734608bda32e验证服务器,因为只允许安全连接。
当我按照上述错误的建议设置配置参数“allowInsecureRegistries”后运行相同的命令时,我得到一个不同的错误,如下所示:-
[错误]无法在项目inventory-service-docker上执行目标com.google.cloud.tools:jib-maven-plugin:1.5.1:build(default-cli):构建图像失败:无法通过注册表示例进行身份验证。 registry.com/inventory-service-docker 因为:sun.security.validator.ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径
看起来我在使用未安全连接到“example.registry.com”的 JIB 时缺少一些配置。