参考文章:Alpine制作JDK8镜像的坑

用Alpine跑了JDK8的镜像结果发现,JDK还是无法执行.后来翻阅文档才发现

Java是基于GUN Standard C library(glibc)

Alpine是基于MUSL libc(mini libc)

所以Alpine需要安装glibc的库,以下是官方给出wiki:

https://wiki.alpinelinux.org/wiki/Running_glibc_programs

至于如何安装,可以参考:

https://github.com/sgerrand/alpine-pkg-glibc

glibc-2.30-r0.apk github官网地址:

https://github.com/sgerrand/alpine-pkg-glibc/releases/

1. Dockerfile文件内容

FROM alpine:latest
#ADD jdk1.8.0_101.tar.gz /usr/local
#ADD jdk-8u231-linux-x64.tar.gz /usr/local
 
#******************更换Alpine源为mirrors.ustc.edu.cn******************
#RUN echo http://mirrors.ustc.edu.cn/alpine/v3.7/main > /etc/apk/repositories && \
#    echo http://mirrors.ustc.edu.cn/alpine/v3.7/community >> /etc/apk/repositories
#RUN apk update && apk upgrade
 
 
#******************Alpine安装 Glibc https://github.com/sgerrand/alpine-pkg-glibc *****************
RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.9/main/" > /etc/apk/repositories && \
wget http://172.17.0.1:8080/jdk-8u231-linux-x64.tar.gz && \
mkdir -p /usr/local/jdk8 && \
mv jdk-8u231-linux-x64.tar.gz /usr/local/jdk8 && \
cd /usr/local/jdk8 && \
tar -xf jdk-8u231-linux-x64.tar.gz && \
rm -rf jdk-8u231-linux-x64.tar.gz && \
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.30-r0/glibc-2.30-r0.apk && \
apk add glibc-2.30-r0.apk && \
rm -rf *.apk && \
rm -rf /var/cache/apk/* 
 
#******************设置JAVA变量环境******************
#ENV JAVA_HOME=/usr/local/jdk1.8.0_101
ENV JAVA_HOME=/usr/local/jdk1.8.0_231
ENV CLASSPATH=$JAVA_HOME/bin
ENV PATH=.:$JAVA_HOME/bin:$PATH
CMD ["java","-version"]

2. 执行docker build指令

$ docker build --rm -t alpine:java .


 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐