Spring Boot:在代理后构建镜像

4
我试图在代理后面构建一个使用Spring Boot 2.3.0的Docker镜像。
根据文档https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/maven-plugin/reference/html/#build-image-example-builder-configuration所述,我需要类似于以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <version>2.3.0.RELEASE</version>
  <configuration>
    <image>
      <env>
        <HTTP_PROXY>http://proxy.example.com</HTTP_PROXY>
        <HTTPS_PROXY>https://proxy.example.com</HTTPS_PROXY>
      </env>
    </image>
  </configuration>
</plugin>

但是我无法让它起作用。不过,我可以在变量前加上BPL_来使其起作用,就像下面这样。

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <version>2.3.0.RELEASE</version>
  <configuration>
    <image>
      <env>
        <BPL_HTTP_PROXY>http://proxy.example.com</BPL_HTTP_PROXY>
        <BPL_HTTPS_PROXY>https://proxy.example.com</BPL_HTTPS_PROXY>
      </env>
    </image>
  </configuration>
</plugin>

这是一个bug吗,还是我没有理解。

更好的方法是,能否在pom文件之外指定,例如命令行? 我正在使用PowerShell。


我也遇到了同样的问题,不过看起来这个功能是在2.4版本中加入的,而不是2.3版本。 - nekperu15739
2
你可以在这里阅读 https://docs.spring.io/spring-boot/docs/2.4.0/maven-plugin/reference/htmlsingle/#build-image-example-builder-configuration 。我已经测试过它,适用于2.4.3版本。 - mrkernelpanic
1
谢谢 @jim-sellers,我一直遇到Get "https://github.com/bell-sw/Liberica/releases/download/11.0.13+8/bellsoft-jre11.0.13+8-linux-amd64.tar.gz": dial tcp 140.82.112.4:443: connect: connection timed out,但是无法确定在哪里配置代理。你的第一个例子使用 <configuration><image><env><HTTP_PROXY/><HTTPS_PROXY/></env></image></configuration> 最终解决了问题。 - wsams
1个回答

2

根据https://docs.spring.io/spring-boot/docs/2.5.6/maven-plugin/reference/htmlsingle/#build-image.examples.builder-configuration,您已接近成功,使用HTTP_PROXY

<groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
        <image>
          <env>
            <HTTP_PROXY>http://some.proxy:3011</HTTP_PROXY>
            <HTTPS_PROXY>http://some.proxy:3011</HTTPS_PROXY>
          </env>
        </image>
 </configuration>

如果您的主机上有代理,并且希望构建包使用它,则可以设置<HTTP_PROXY>http://host.docker.internal:3011</HTTP_PROXY><HTTPS_PROXY>http://host.docker.internal:3011</HTTPS_PROXY>。其中host.docker.internal是运行在容器内部的命令所在主机的IP地址。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接