Docker JDK镜像

时间:2022-06-15 11:12:42

Docker jdk镜像

说明

  1. 使用alpine-glibc作为基础镜像
  2. JAVA JDK/JRE以1.8为基准

下载文件

1.下载JDK/JRE压缩包。

jre-8u201-linux-x64.tar.gz

Docker JDK镜像

jdk-8u201-linux-x64.tar.gz

Docker JDK镜像

创建Dockerfile

  • JDK
FROM docker.io/jeanblanchard/alpine-glibc
ADD ./package/jdk-8u201-linux-x64.tar.gz /usr/local/docker/java/jdk/
ENV JAVA_HOME=/usr/local/docker/java/jdk/jdk1.8.0_201
ENV CLASSPATH=$JAVA_HOME/bin
ENV PATH=.:$JAVA_HOME/bin:$PATH
CMD ["java","-version"]
  • JRE
# using apline-glibc instead of apline is mainly because JDK relies on glibc
FROM docker.io/jeanblanchard/alpine-glibc
# add jdk
ADD ./package/jre-8u201-linux-x64.tar.gz /usr/local/docker/java/jdk/
# env
ENV JAVA_HOME=/usr/local/docker/java/jdk/jre1.8.0_201
ENV CLASSPATH=$JAVA_HOME/bin
ENV PATH=.:$JAVA_HOME/bin:$PATH
# workdir
WORKDIR /opt
# cmd
CMD ["java","-version"]

构建

.表示Dockerfile文件在当前目录。格式:docker build -t 镜像名称:tag 空格.

  • jre
docker build -t java/jre1.8.0:201 .
  • jdk
docker build -t java.jdk1.8.0:201 .

查看镜像

REPOSITORY TAG IMAGE ID CREATED SIZE
java/jdk1.8.0 201 8e99cccdb738 About a minute ago 408MB
java/jre1.8.0 201 4b2b3e1e96e8 4 hours ago 240MB

测试运行

  • jre
# docker run -it java/jre1.8.0:201 /bin/sh
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
  • jdk
# docker run -it java/jdk1.8.0:201 /bin/sh
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

操作提示

ctrl+p ctrl+q 退出当前容器。