方法一:构建好的镜像
[root@node1 tmp]# docker image ls | grep jdk
hlwojiv/alpine-jdk8 latest f726e71fd441 5 months ago 237MB
[root@node1 tmp]# docker pull hlwojiv/alpine-jdk8
[root@node1 tmp]# docker run -it --rm hlwojiv/alpine-jdk8 /usr/glibc-compat/bin/locale -a | grep zh
zh_CN.utf8
zh_HK.utf8
zh_SG.utf8
zh_TW.utf8
[root@node1 tmp]# docker run -it --rm hlwojiv/alpine-jdk8 env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/java/jdk/bin
HOSTNAME=ebb732aa197d
TERM=xterm
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
JAVA_HOME=/usr/java/jdk
HOME=/root
方法二:使用dcokerfile构建
$ git clone https://github.com/hlwojiv/docker-alpine-jdk8.git
$ cd docker-alpine-jdk8/
$ ls
Dockerfile README.md jre8.tar.gz locale.md
$ cat Dockerfile
FROM docker.io/jeanblanchard/alpine-glibc
MAINTAINER hlwojiv
ADD jre8.tar.gz /usr/java/jdk/
RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories \
&& echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/community' >>/etc/apk/repositories \
&& apk update && apk add tzdata \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
RUN apk --no-cache add ca-certificates wget && \
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-bin-2.25-r0.apk && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-i18n-2.25-r0.apk && \
apk add glibc-bin-2.25-r0.apk glibc-i18n-2.25-r0.apk glibc-2.25-r0.apk
# Iterate through all locale and install it
# Note that locale -a is not available in alpine linux, use `/usr/glibc-compat/bin/locale -a` instead
COPY ./locale.md /locale.md
RUN cat locale.md | xargs -i /usr/glibc-compat/bin/localedef -i {} -f UTF-8 {}.UTF-8
# Set the lang, you can also specify it as as environment variable through docker-compose.yml
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8
ENV JAVA_HOME /usr/java/jdk
ENV PATH ${PATH}:${JAVA_HOME}/bin
WORKDIR /opt
$ cat locale.md
en_US
zh_CN
$ docker build -t alpine-utf8-jdk .
# 构建报错,locale.md某些语言报错
cannot open locale definition file `iw_IL': No such file or directory
cannot open locale definition file `no_NO': No such file or directory
cannot open locale definition file `pap_AN': No such file or directory
在dockerfile中修改语言环境
FROM alpine:3.6
# ---not shown here---
# Install language pack
RUN apk --no-cache add ca-certificates wget && \
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-bin-2.25-r0.apk && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-i18n-2.25-r0.apk && \
apk add glibc-bin-2.25-r0.apk glibc-i18n-2.25-r0.apk glibc-2.25-r0.apk
# Iterate through all locale and install it
# Note that locale -a is not available in alpine linux, use `/usr/glibc-compat/bin/locale -a` instead
COPY ./locale.md /locale.md
RUN cat locale.md | xargs -i /usr/glibc-compat/bin/localedef -i {} -f UTF-8 {}.UTF-8
# Set the lang, you can also specify it as as environment variable through docker-compose.yml
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8
小结:
删了一些东西,重新构建
Dockerfile
FROM docker.io/jeanblanchard/alpine-glibc
COPY ./locale.md /locale.md
# Install language pack
#RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories \
# && echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/community' >>/etc/apk/repositories \
RUN apk update \
&& apk add tzdata \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& apk del tzdata \
&& apk --no-cache add ca-certificates wget \
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk \
https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-bin-2.25-r0.apk \
https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-i18n-2.25-r0.apk \
&& apk add glibc-bin-2.25-r0.apk glibc-i18n-2.25-r0.apk glibc-2.25-r0.apk \
&& sleep 3 \
&& cat /locale.md | xargs -i /usr/glibc-compat/bin/localedef -i {} -f UTF-8 {}.UTF-8 \
&& rm /etc/apk/keys/sgerrand.rsa.pub \
&& rm /locale.md \
glibc-2.25-r0.apk \
glibc-bin-2.25-r0.apk \
glibc-i18n-2.25-r0.apk \
&& apk del wget ca-certificates\
&& rm -rf /var/cache/apk/* \
&& rm "/root/.wget-hsts"
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8
locale.md
[root@glowing-bliss-1 tmp]# cat locale.md
en_AG
en_AU
en_BW
en_CA
en_DK
en_GB
en_HK
en_IE
en_IN
en_NG
en_NZ
en_PH
en_SG
en_US
en_ZA
en_ZM
en_ZW
zh_CN
zh_HK
zh_SG
zh_TW
zu_ZA
[root@glowing-bliss-1 tmp]# docker build -t my:v0.6 .
[root@glowing-bliss-1 tmp]# docker images | grep v0.6
my v0.6 29a1b86617b0 4 minutes ago 37.7MB
[root@glowing-bliss-1 tmp]# docker run --rm -it my:v0.6 env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=ca966becfb4c
TERM=xterm
GLIBC_VERSION=2.30-r0
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
HOME=/root
failed to resize tty, using default size
[root@glowing-bliss-1 tmp]# docker run --rm -it my:v0.6 /usr/glibc-compat/bin/locale -a | grep zh
zh_CN.utf8
zh_HK.utf8
zh_SG.utf8
zh_TW.utf8
- 文章链接: https://blog.zhangcun.store/2022/04/21/alpine-jing-xiang-tian-jia-zh-cn-utf8/
- 版权声明: 本网站所有文章除特别声明外,均采用 CC BY-NC-ND 4.0 许可协议。转载请注明出处!
你的赏识是我前进的动力
支付宝
微信