How to change locale in Liberty Container image
Tags: websphere, liberty, containers, docker
Published: 2023-04-27 02:46:20

So you got WebSphere Liberty Container image based on Ubuntu from [here](https://hub.docker.com/_/websphere-liberty).
And you'd like to change locale because you'd like to have logs in another language, such as Japanese, etc.
My procedure in this post is based on [this](https://hub.docker.com/_/websphere-liberty) but I think you need some additional steps, so here is how.
By the way my environment is MacOS Monterey 23.6.5, Apple M1Pro,using podman instead of docker. That's why I pulled amd64, of course you can get other architecture images depending on your environment.

1.Make Containerfile to install JP locale package and set environment variables with root.

```
FROM docker.io/amd64/websphere-liberty:23.0.0.3-full-java17-openj9
USER 0
RUN apt-get update \
 && apt-get install -y language-pack-ja \
 && rm -rf /var/lib/apt/lists/*
ENV LANG=ja_JP.UTF-8 \
  LANGUAGE=ja_JP:ja \
  LC_ALL=ja_JP.UTF-8 \
  TZ="Asia/Tokyo"
USER 1001

```

2.Build image.

```
$ podman build -t amd64-websphere-liberty:23.0.0.3-full-java17-openj9-jp .
STEP 1/5: FROM docker.io/amd64/websphere-liberty:23.0.0.3-full-java17-openj9
STEP 2/5: USER 0
--> Using cache 5d96bfdaf8d57c662ee86745b993e848d14849982ab17d543c9a872dbd469da2
--> 5d96bfdaf8d
STEP 3/5: RUN apt-get update  && apt-get install -y language-pack-ja  && rm -rf /var/lib/apt/lists/*
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:5 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [2,632 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1,275 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [28.5 kB]
Get:8 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [1,035 kB]
Get:9 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [2,145 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:13 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [31.2 kB]
Get:14 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1,331 kB]
Get:15 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [2,308 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [3,125 kB]
Get:17 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [28.6 kB]
Get:18 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [55.2 kB]
Fetched 26.2 MB in 20s (1,305 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
 language-pack-ja-base
The following NEW packages will be installed:
 language-pack-ja language-pack-ja-base
0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded.
Need to get 1,673 kB of archives.
After this operation, 7,786 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 language-pack-ja-base all 1:20.04+20220818 [1,671 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 language-pack-ja all 1:20.04+20220818 [1,900 B]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 1,673 kB in 2s (899 kB/s)
Selecting previously unselected package language-pack-ja-base.
(Reading database ... 7344 files and directories currently installed.)
Preparing to unpack .../language-pack-ja-base_1%3a20.04+20220818_all.deb ...
Unpacking language-pack-ja-base (1:20.04+20220818) ...
Selecting previously unselected package language-pack-ja.
Preparing to unpack .../language-pack-ja_1%3a20.04+20220818_all.deb ...
Unpacking language-pack-ja (1:20.04+20220818) ...
Setting up language-pack-ja (1:20.04+20220818) ...
Setting up language-pack-ja-base (1:20.04+20220818) ...
Generating locales (this might take a while)...
 ja_JP.UTF-8... done
Generation complete.
--> 64f2583a73b
STEP 4/5: ENV LANG=ja_JP.UTF-8   LANGUAGE=ja_JP:ja   LC_ALL=ja_JP.UTF-8   TZ="Asia/Tokyo"
--> 7aade810f7c
STEP 5/5: USER 1001
COMMIT amd64-websphere-liberty:23.0.0.3-full-java17-openj9-jp
--> 78bbe9bddab
Successfully tagged localhost/amd64-websphere-liberty:23.0.0.3-full-java17-openj9-jp
78bbe9bddab06db1abaca8c6d0b8e2ca59908ea979ec07adb833714f50ed8d00
```

3.Run from the image and see if successfully running.

```
$ podman images
REPOSITORY                                   TAG               IMAGE ID   CREATED    SIZE
localhost/amd64-websphere-liberty                       23.0.0.3-full-java17-openj9-jp 78bbe9bddab0 6 seconds ago 828 MB
 
$ podman run -d -p 9080:9080 -p 9443:9443 --name libertypodman localhost/amd64-websphere-liberty:23.0.0.3-full-java17-openj9-jp
5194c9971675cf84ce8dc9b609c7c44b44ea74c5b3b29f421d68ba47a318a8ba
 
$ podman ps -a
CONTAINER ID IMAGE                               COMMAND        CREATED    STATUS    PORTS                      NAMES
5194c9971675 localhost/amd64-websphere-liberty:23.0.0.3-full-java17-openj9-jp /opt/ibm/wlp/bin/... 4 seconds ago Up 4 seconds 0.0.0.0:9080->9080/tcp, 0.0.0.0:9443->9443/tcp libertypodman
```

4.Check the inside of the container to check if JP locale is set and logs are written in JP.

```
$ podman exec -it libertypodman /bin/sh
$ locale -a
C
C.UTF-8
POSIX
en_US.utf8
ja_JP.utf8

$ locale
LANG=ja_JP.UTF-8
LANGUAGE=ja_JP:ja
LC_CTYPE="ja_JP.UTF-8"
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME="ja_JP.UTF-8"
LC_COLLATE="ja_JP.UTF-8"
LC_MONETARY="ja_JP.UTF-8"
LC_MESSAGES="ja_JP.UTF-8"
LC_PAPER="ja_JP.UTF-8"
LC_NAME="ja_JP.UTF-8"
LC_ADDRESS="ja_JP.UTF-8"
LC_TELEPHONE="ja_JP.UTF-8"
LC_MEASUREMENT="ja_JP.UTF-8"
LC_IDENTIFICATION="ja_JP.UTF-8"
LC_ALL=ja_JP.UTF-8

$ cd logs
$ ls
messages.log
$ cat messages.log
********************************************************************************
product = WebSphere Application Server 23.0.0.3 (wlp-1.0.75.cl230320230319-1900)
wlp.install.dir = /opt/ibm/wlp/
server.output.dir = /opt/ibm/wlp/output/defaultServer/
java.home = /opt/java/openjdk
java.version = 17.0.6
java.runtime = IBM Semeru Runtime Open Edition (17.0.6+10)
os = Linux (5.17.5-300.fc36.aarch64; amd64) (ja_JP)
process = 1@5194c9971675
Classpath = /opt/ibm/wlp/bin/tools/ws-server.jar:/opt/ibm/wlp/bin/tools/ws-javaagent.jar
Java Library path = /opt/java/openjdk/lib/default:/opt/java/openjdk/lib:/usr/lib64:/usr/lib
********************************************************************************
[2023/04/26 14:21:22:376 JST] 00000001 com.ibm.ws.kernel.launch.internal.FrameworkManager      A CWWKE0001I: サーバー defaultServer が起動されました。
[2023/04/26 14:21:23:008 JST] 00000001 com.ibm.ws.kernel.launch.internal.FrameworkManager      A CWWKE0100I: この製品は、開発使用向け、および限定的な実動使用向けにライセンスが交付されています。 全ライセンス条項は以下で表示可能です: https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/license/base_ilan/ilan/23.0.0.3/lafiles/ja.html
$ exit
```

Thanks.