I can set locale with CentOS image with
FROM centos
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
But It seems not work with Alpine image. How can I set locale with Alpine image?
I can set locale with CentOS image with
FROM centos
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
But It seems not work with Alpine image. How can I set locale with Alpine image?
It works for me, Dockerfile:
FROM openjdk:8-jdk-alpine
RUN apk update
RUN apk add tzdata
RUN cp /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime
RUN rm -r /usr/share/zoneinfo/Africa && \
rm -r /usr/share/zoneinfo/Antarctica && \
rm -r /usr/share/zoneinfo/Arctic && \
rm -r /usr/share/zoneinfo/Asia && \
rm -r /usr/share/zoneinfo/Atlantic && \
rm -r /usr/share/zoneinfo/Australia && \
rm -r /usr/share/zoneinfo/Europe && \
rm -r /usr/share/zoneinfo/Indian && \
rm -r /usr/share/zoneinfo/Mexico && \
rm -r /usr/share/zoneinfo/Pacific && \
rm -r /usr/share/zoneinfo/Chile && \
rm -r /usr/share/zoneinfo/Canada
RUN echo "America/Sao_Paulo" > /etc/timezone
ENV TZ America/Sao_Paulo
ENV LANG pt_BR.UTF-8
ENV LANGUAGE pt_BR.UTF-8
ENV LC_ALL pt_BR.UTF-8
ARG JAR_FILE
ADD ${JAR_FILE} /app/
RUN mv /app/${JAR_FILE} /app/app.jar
ENTRYPOINT java $JAVA_OPTS -jar /app/app.jar
&&
between the commands. –
Changeover This is how I setup my time & encodings when containerizing an application in Alpine Linux.
The following is tested and known to work correctly as of Alpine Linux version 3.16:
In the Dockerfile
:
Install required packages:
RUN apk add --no-cache --update musl musl-utils musl-locales tzdata
Set timezone from the choices in /usr/share/zoneinfo/
:
ENV TZ=Europe/London
RUN cp /usr/share/zoneinfo/Europe/London /etc/localtime
In /usr/share/i18n/locales/musl
, Musl
will install the following encodings:
cs_CZ.UTF-8
de_CH.UTF-8
de_DE.UTF-8
en_GB.UTF-8
en_US.UTF-8
es_ES.UTF-8
fi_FI.UTF-8
fr_FR.UTF-8
it_IT.UTF-8
nb_NO.UTF-8
nl_NL.UTF-8
pt_BR.UTF-8
pt_PT.UTF-8
ru_RU.UTF-8
sr_RS.UTF-8
sv_SE.UTF-8
Choose your preferred encoding from the above list and substitute it for en_GB.UTF-8
if you don't want GB English in the following lines of your Dockerfile:
RUN echo 'export LC_ALL=en_GB.UTF-8' >> /etc/profile.d/locale.sh && \
sed -i 's|LANG=C.UTF-8|LANG=en_GB.UTF-8|' /etc/profile.d/locale.sh
Although you have to sed
the LANG=
parameter, by appending export LC_ALL=
to the end of /etc/profile.d/locale.sh
the rest is done for you.
After the build, when you now execute:
locale
You'll see the default encodings have changed FROM C.UTF-8
TO en_GB.UTF-8
:
bash-5.1# locale
LANG=en_GB.UTF-8
LC_CTYPE=en_GB.UTF-8
LC_NUMERIC=en_GB.UTF-8
LC_TIME=en_GB.UTF-8
LC_COLLATE=en_GB.UTF-8
LC_MONETARY=en_GB.UTF-8
LC_MESSAGES=en_GB.UTF-8
LC_ALL=en_GB.UTF-8
bash-5.1#
And when you execute:
date
You'll note the the time has now changed FROM UTC
TO BST
:
Mon Jul 18 16:59:51 BST 2022
Finally, some notes worth reading on Alpine's Musl
implementation of locales is HERE
There is a cleaner way using apk del tzdata
, described here:
apk add
), configure the timezone, and optionally remove the package. But this is not what OP was asking for. –
Ammadis uclibc
, not musl
or glibc
–
Spitler © 2022 - 2024 — McMap. All rights reserved.