创建Dockerfile
FROM centos:7
MAINTAINER liguanqiao
# 下载jdk1.8
ADD jdk-8u231-linux-x64.tar.gz /usr/local/
ENV JAVA_HOME /usr/local/jdk1.8.0_231
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH $PATH:$JAVA_HOME/bin
构建镜像
docker build -t liguanqiao/jdk:8u231
查看镜像
docker images
启动容器
docker run -d -t --name jdk8 liguanqiao/jdk:8u231
进入容器
docker exec -it jdk8 /bin/bash
测试
java -version
结果
[root@f6beab6e383d /]# java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
大功告成~~~
评论区