Docker JDK镜像

Docker jdk镜像

说明

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

下载文件

1.下载JDK/JRE压缩包。

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

技术分享图片

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

技术分享图片

创建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
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
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 退出当前容器。

文章来自:https://www.cnblogs.com/lenovo_tiger_love/p/Docker.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3