How to set locale in Docker Alpine?

天大地大妈咪最大 提交于 2020-12-05 05:02:55

问题


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?


回答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



回答2:


There is a cleaner way using apk del tzdata, described here:

Setting the timezone - Alpine Linux



来源:https://stackoverflow.com/questions/49042223/how-to-set-locale-in-docker-alpine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!