How to set locale in Docker Alpine?
19,064
Solution 1
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
Solution 2
There is a cleaner way using apk del tzdata
, described here:
Setting the timezone - Alpine Linux
Related videos on Youtube
Author by
Kevin
Updated on June 04, 2022Comments
-
Kevin over 1 year
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?
-
goetzc about 4 yearsFirst you need to install the page (
apk add
), configure the timezone, and optionally remove the package. But this is not what OP was asking for. -
akauppi about 2 yearsRemoving the unneeded files in the way you do doesn't really reduce the size of the image. If that is the intention, gather them in one RUN and use
&&
between the commands.