Change system locale inside a CentOS/RHEL without using localectl?
Asked Answered
M

1

9

I'm trying to build a Docker image based on oracle/database:11.2.0.2-xe (which is based on Oracle Linux based on RHEL) and want to change the system locale in this image (using some RUN command inside a Dockerfile).

According to this guide I should use localectl set-locale <MYLOCALE> but this command is failing with Failed to create bus connection: No such file or directory message. This is a known Docker issue for commands that require SystemD to be launched.

I tried to start the SystemD anyway (using /usr/sbin/init as first process as well as using -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v /run thanks to this help) but then the localectl set-locale failed with Could not get properties: Connection timed out message.

So I'm now trying to avoid the usage of localectl to change my system globale locale, how could I do this?

Monde answered 19/9, 2018 at 8:42 Comment(0)
M
10

According to this good guide on setting locale on Linux, I should use

localedef -c -i fr_FR -f ISO-8859-15 fr_FR.ISO-8859-15

But this command failed with

cannot read character map directory `/usr/share/i18n/charmaps': No such file or directory`

This SO reply indicated one could use yum reinstall glibc-common -y to fix this and it worked.

So my final working Dockerfile is:

RUN yum reinstall glibc-common -y && \
  localedef -c -i fr_FR -f ISO-8859-15 fr_FR.ISO-8859-15 && \
  echo "LANG=fr_FR.ISO-8859-15" > /etc/locale.conf

ENV LANG fr_FR.ISO-8859-15
Monde answered 19/9, 2018 at 9:17 Comment(2)
for ol8 (ORACLE Linux) oraclelinux8: microdnf install glibc-langpack-ru localedef -i ru_RU -f UTF-8 ru_RU.UTF-8 echo "LANG=ru_RU.UTF-8" > /etc/locale.conf for Russian (русской) locale at openjdk:11.0.11-oracle docker container export LANG=ru_RU.UTF-8 OR ENV LANG ru_RU.UTF-8 to DockerfileJolee
It didn't work for me in ubi8 out of the box. To make it work you have to install glibc-locale-source package. Otherwise localedef will complain: [error] character map file UTF-8 not found: No such file or directoryThornie

© 2022 - 2024 — McMap. All rights reserved.