【问题标题】:How to change docker image built with spring-boot-maven-plugin env from POSIX to C.UTF-8 out of box如何将使用 spring-boot-maven-plugin env 构建的 docker 镜像从 POSIX 更改为开箱即用的 C.UTF-8
【发布时间】:2023-01-26 19:19:53
【问题描述】:

当我构建图像并从容器中检查locale

mvn spring-boot:build-image
docker run myimage
docker exec -it <id> locale

我有

LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

我的应用程序在非 ASCII 字符串上失败

java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters: ...
at java.base/sun.nio.fs.UnixPath.encode(Unknown Source)
at java.base/sun.nio.fs.UnixPath.(Unknown Source)
at java.base/sun.nio.fs.UnixFileSystem.getPath(Unknown Source)
at java.base/java.nio.file.Path.resolve(Unknown Source)

UTF-8 字符集修复错误

docker run -e LANG=C.UTF-8 myimage

我想将 LANG env 默认值添加到图像。我怎样才能做到这一点?

【问题讨论】:

    标签: spring-boot


    【解决方案1】:

    配置

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <image>
                <env>
                    <BPE_LANG>C.UTF-8</BPE_LANG>
                </env>
            </image>
        </configuration>
    </plugin>
    

    尽管 docker exec -it &lt;id&gt; locale 显示 POSIX,但修复了问题。

    这是scottfrederick的建议。我非常感谢你!

    【讨论】:

      【解决方案2】:

      我应该如何设置gradle? 这不行

      tasks.named("bootBuildImage") {
        environment["BPE_LANG"] = "C.UTF-8"
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-07
        • 1970-01-01
        • 1970-01-01
        • 2020-07-06
        • 2021-03-03
        • 2023-01-09
        • 2019-07-13
        • 2018-05-06
        相关资源
        最近更新 更多