直接使用镜像:frolvlad/alpine-oraclejre8:slim --> 不支持bash pivotalservices/jdk8-minimal:latest --> 支持bash ,可以执行shell
参考:
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 glibc
FROM docker.io/jeanblanchard/alpine-glibc
# author
MAINTAINER scc <shangchengcai@voole.com>
# A streamlined jre
ADD jre8.tar.gz /usr/java/jdk/
# set env
ENV JAVA_HOME /usr/java/jdk
ENV 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 -version
java 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)