直接使用镜像:frolvlad/alpine-oraclejre8:slim
参考:
https://my.oschina.net/shyloveliyi/blog/1627020
1、首先下载jre,下载地址是https://www.java.com/en/download/manual.jsp,大概是77M。
2、解压jre包,删除根目录下文本文件,然后删除其他不必要文件。
#解压tar xvcf jre-8u161-linux-x64.tar.gz#进入目录cd jre1.8.0_161/#删除文本文件rm -rf COPYRIGHT LICENSE README release THIRDPARTYLICENSEREADME-JAVAFX.txtTHIRDPARTYLICENSEREADME.txt Welcome.html#删除其他无用文件 rm -rf lib/plugin.jar \ lib/ext/jfxrt.jar \ bin/javaws \ lib/javaws.jar \ lib/desktop \ plugin \ 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
3、重新打包所有文件(不打包也可以,在Dockerfile里ADD这个目录即可,当前精简完jre目录大小是107M,压缩后是41M)
tar zcvf jre8.tar.gz *
4、创建Dockerfile
# using alpine-glibc instead of alpine is mainly because JDK relies on glibcFROM docker.io/jeanblanchard/alpine-glibc# authorMAINTAINER scc# A streamlined jreADD jre8.tar.gz /usr/java/jdk/# set envENV JAVA_HOME /usr/java/jdkENV PATH ${PATH}:${JAVA_HOME}/bin # run container with base path:/opt WORKDIR /opt
5、构建(整体大小是122M)
docker build -t voole/java8:1.0 .
6、测试运行
# docker run -it voole/java8:1.0/opt # java -versionjava version "1.8.0_161"Java(TM) SE Runtime Environment (build 1.8.0_161-b12)Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)