spring-bootdockerlocalecloud-foundrybuildpack

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=

Solution

  • 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.