1

我正在尝试使用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 命令行成功地PULLPUSH图像到“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 时缺少一些配置。

4

1 回答 1

0

(在我开始之前,请不要使用 Jib 1.5.x,因为这些版本存在网络性能问题。)

JVM 不使用 Windows 证书存储。这个文件

JRE 的一个大问题是它完全忽略了 Windows 证书存储。它不使用 Windows 证书存储,而是使用自己的实现

我刚刚在另一个答案中找到的 Windows 的一个潜在选择是使用-Djavax.net.ssl.trustStoreType=WINDOWS-ROOT. 但我还没有验证自己是否可行。

另一种方法是将您的证书添加到默认的 Java 证书存储 (truststore) 文件 ( cacerts)。它通常位于<JDK>/lib/sercurity/或下<JRE>/jre/lib/security/

有多种添加证书的方法(例如,使用各种 GUI 工具)。例如,

  • 在命令行上
keytool.exe -import -storepass "changeit" -keystore "C:\Program Files (x86)\Java\jre1.8.0_144\lib\security\cacerts" -alias certificate.cer -file "C:\certificate.cer" -noprompt
  • 使用名为KeyStore Explorer的 GUI 工具

最后,对于那些想要获得更多解决此类 Java 证书问题的想法的人,请查看此评论

于 2019-10-03T17:13:50.227 回答