arielnmz
arielnmz

Reputation: 9145

How to change locale settings on Fedora Docker container?

On a normal server e.g. a Linode VPS I would normally do:

localectl set-locale LANG=<locale>.utf8
timedatectl set-timezone <timezone>

But since systemd is not present or does not work on containers I get:

Failed to create bus connection: No such file or directory

Now, my goal is just to change these settings without using systemd but such approach seems to go undocumented. Is there a reference for non-systemd alternatives to config tools?

Upvotes: 7

Views: 5853

Answers (4)

Bhavin Solanki
Bhavin Solanki

Reputation: 4818

Based on a technique used in sti-base, I came up with the following workaround for https://github.com/ncoghlan/fedbuildenv/blob/09a18d91e7af64a45394669bac2595a4b628960d/Dockerfile#L26:

# Set a useful default locale
RUN echo "export LANG=en_US.utf-8" > /opt/export_LANG.sh
ENV BASH_ENV=/opt/export_LANG.sh \
    ENV=/opt/export_LANG.sh \
    PROMPT_COMMAND="source /opt/export_LANG.sh"

BASH_ENV covers non-interactive bash sessions, ENV covers sh sessions, and PROMPT_COMMAND covers interactive bash sessions.

this seems to be the debians's equivalent of locale-gen:

RUN localedef -v -c -i fr_FR -f UTF-8 fr_FR.UTF-8 || true

Upvotes: -1

Sreekanth
Sreekanth

Reputation: 378

Edit .bash_profile or .bashrc from root and add the following.

TZ='Asia/Kolkata'
export TZ

Save file and commit image after its done.

Upvotes: -1

Chad
Chad

Reputation: 11

Put this in your Dockerfile

ENV TZ=America/Denver
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

Upvotes: 0

mviereck
mviereck

Reputation: 1399

Some documentation about locale setting in arch wiki: https://wiki.archlinux.org/index.php/locale

In Dockerfile, adjust LANG to your desired locale. You can add more than one locale in /etc/locale.gen to have a choice later.

Works on debian, arch, but locale-gen misses on fedora:

ENV LANG=en_US.utf8
RUN echo "$LANG UTF-8" >> /etc/locale.gen
RUN locale-gen
RUN update-locale --reset LANG=$LANG

More general is localedef, works on fedora, too:

ENV LANG=en_US.UTF-8
localedef --verbose --force -i en_US -f UTF-8 en_US.UTF-8

Upvotes: 3

Related Questions