Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

How can the locale and encoding set in cloudfoundry buildpack docker image built by spring boot gradle task "bootBuildImage"

When I create a docker image with a spring boot app, I see encoding problems in filenames of directories mounted into the running container with the spring boot app. I create the docker image by the gradle task bootBuildImage as described here.

When I look into the running container, I see the locale is set to posix. In a regular Dockerfile I would run the appropriate commands to setup a german utf-8 locale setting. But spring boot is using cloud foundry buildpacks and I can find no place to hook into for the locale setting. How can I adjust the locale for the image in the build process?

cnb@9d24bfe67b9e:/$ 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=

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

By default, the Spring Boot Gradle plugin uses the Paketo builder image and run image. The run image provides the base OS layer for the generated app image, and this is where the locale is coming from.

One way to override the locale would be to generate a custom run image based on the Paketo run image and setup the locale in your custom run image. A Dockerfile for the custom run image might look something like this:

FROM paketobuildpacks/run:base-cnb

USER root
RUN apt-get install -y locales
RUN locale-gen de_DE.utf8
ENV LANG de_DE.UTF-8
ENV LANGUAGE de_DE:de
ENV LC_ALL de_DE.UTF-8

Once you've built and tagged the custom run image, you can override the default run image in the Spring Boot Gradle plugin configuration with the runImage property or on the command line with the ---runImage flag.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...