0%

构建最小的java8镜像

问题

  • openjdkoracle jdk一些情况下并不兼容;
  • openjdk镜像很小只有一百朵兆,但是oracle jdk搜到的镜像都很大.

步骤

  1. 下载最新的oracle jre 8
https://javadl.oracle.com/webapps/download/AutoDL?BundleId=242050_3d5a2bb8f8d4428bbe94aed7ec7ae784
  1. 上传到linux并解压
[root@node1 jdk8]# tar -xvzf jre-8u251-linux-x64.tar.gz 
[root@node1 jdk8]# pwd
/root/jdk8
[root@node1 jdk8]# ll
总用量 85492
drwxr-xr-x 5 10143 10143       76 7月   9 14:04 jre1.8.0_251
-rw-r--r-- 1 root  root  87543611 7月   9 13:55 jre-8u251-linux-x64.tar.gz
  1. 删除一些说明文档和无用包
[root@node1 jdk8]# cd jre1.8.0_251/

rm -rf COPYRIGHT LICENSE README release THIRDPARTYLICENSEREADME-JAVAFX.txt THIRDPARTYLICENSEREADME.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

[root@node1 jre1.8.0_251]# ll
总用量 4
drwxr-xr-x  2 10143 10143  208 7月   9 13:56 bin
drwxr-xr-x 13 10143 10143 4096 7月   9 13:56 lib
drwxr-xr-x  4 10143 10143   47 3月  12 14:33 man
  1. 重新打包
[root@node1 jre1.8.0_251]# tar zcvf jre8.tar.gz *
[root@node1 jre1.8.0_251]# ll
总用量 43896
drwxr-xr-x  2 10143 10143      208 7月   9 13:56 bin
-rw-r--r--  1 root  root  44942683 7月   9 14:04 jre8.tar.gz
drwxr-xr-x 13 10143 10143     4096 7月   9 13:56 lib
drwxr-xr-x  4 10143 10143       47 3月  12 14:33 man
  1. 直接在当前目录下创建Dockerfile
[root@node1 jre1.8.0_251]# vim Dockerfile

编写Dockerfile

FROM docker.io/jeanblanchard/alpine-glibc
MAINTAINER wuzhiyong
ADD jre8.tar.gz /usr/java/jdk/
ENV JAVA_HOME /usr/java/jdk
ENV PATH ${PATH}:${JAVA_HOME}/bin
WORKDIR /opt
  1. 生成镜像
# 生成镜像
[root@node1 jre1.8.0_251]# docker build -t wuzhiyong/java8.0_251 .
Sending build context to Docker daemon  161.1MB
Step 1/6 : FROM docker.io/jeanblanchard/alpine-glibc
 ---> c1bfe6541128
Step 2/6 : MAINTAINER wuzhiyong
 ---> Using cache
 ---> 5e4699308c35
Step 3/6 : ADD jre8.tar.gz /usr/java/jdk/
 ---> 8b6b66ec0f68
Step 4/6 : ENV JAVA_HOME /usr/java/jdk
 ---> Running in 26f286188aa8
Removing intermediate container 26f286188aa8
 ---> 7d1501133f4c
Step 5/6 : ENV PATH ${PATH}:${JAVA_HOME}/bin
 ---> Running in 418be370f8b9
Removing intermediate container 418be370f8b9
 ---> 8a920d8285df
Step 6/6 : WORKDIR /opt
 ---> Running in 107687a0007d
Removing intermediate container 107687a0007d
 ---> e7a62387e585
Successfully built e7a62387e585
Successfully tagged wuzhiyong/java8.0_251:latest
#查看镜像大小
[root@node1 jre1.8.0_251]# docker images | grep java8
wuzhiyong/java8.0_251                                            latest                    e7a62387e585        15 seconds ago      133MB
  1. 上传到镜像仓库,可以下载使用
docker pull hub.deri.org.cn/library/oracle_jdk_1.8_251:latest