一、下载文件
-
glibc
下载地址
glibc-2.35-r1.apk
glibc-bin-2.35-r1.apk
glibc-i18n-2.35-r1.apk -
rsa
sgerrand.rsa.pub -
jre 1.8
jre-8u201-linux-x64.tar.gz
二、精简JRE
- 解压
tar -zxvf jre-8u201-linux-x64.tar.gz && mv jre1.8.0_201 jre
- 精简
cd jre && rm -rf !(bin|lib|man) && \
rm -rf ./lib/plugin.jar \
./lib/ext/jfxrt.jar \
./bin/javaws \
./lib/javaws.jar \
./lib/desktop \
./lib/deploy* \
./lib/*javafx* \
./lib/*jfx* \
./lib/amd64/libdecora_sse.so \
./lib/amd64/libprism_*.so \
./lib/amd64/libfxplugins.so \
./lib/amd64/libglass.so \
/lib/amd64/libgstreamer-lite.so \
./lib/amd64/libjavafx*.so \
./lib/amd64/libjfx*.so \
./lib/locale/!(zh*)
- 压缩
cd .. && tar zcvf jre.tar.gz jre/
三、Dockerfile
FROM alpine:3.18.6
WORKDIR /home
# 更换aline源、update
RUN echo "http://mirrors.aliyun.com/alpine/v3.18/community" > /etc/apk/repositories
RUN echo "http://mirrors.aliyun.com/alpine/v3.18/main" >> /etc/apk/repositories
RUN apk update && apk upgrade
RUN apk --no-cache add ca-certificates bash net-tools tzdata dmidecode
RUN rm -rf /var/cache/apk/*
# 安装glibc
COPY apk/glibc-2.35-r1.apk .
COPY apk/glibc-bin-2.35-r1.apk .
COPY apk/glibc-i18n-2.35-r1.apk .
COPY apk/sgerrand.rsa.pub /etc/apk/keys/sgerrand.rsa.pub
RUN apk add glibc-2.35-r1.apk glibc-bin-2.35-r1.apk glibc-i18n-2.35-r1.apk
RUN rm -rf *.apk
# 设置时间
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 解决中文乱码
RUN /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8
ENV LANG=en_US.UTF-8
# 安装jre
ADD jre.tar.gz .
RUN chmod +x /home/jre
ENV JAVA_HOME=/home/jre
ENV PATH=$PATH:.:$JAVA_HOME/bin
四、构建镜像
- 文件目录
- 构建镜像
docker build --tag java:1.8.0 .
五、容器测试
- 进入容器
docker run -it --privileged -v /dev/mem:/dev/mem \
-v /sys/class/net/ens160/address:/home/address --rm java:1.8.0 bash
- 测试