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

Dockerfile

FROM alpine:latest
ADD jdk1.8.0_101.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 apk --no-cache add ca-certificates && \
    wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub && \
    wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.27-r0/glibc-2.27-r0.apk && \
    apk add glibc-2.27-r0.apk


******************设置JAVA变量环境******************
ENV JAVA_HOME=/usr/local/jdk1.8.0_101
ENV CLASSPATH=$JAVA_HOME/bin
ENV PATH=.:$JAVA_HOME/bin:$PATH
CMD ["java","-version"]

 

你可能感兴趣的:(Docker)