1、yum命令安装jdk
选择版本安装
yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
或者如下命令,安装jdk1.8.0的所有文件
yum install -y java-1.8.0-openjdk*
yum install -y java-1.8.0-openjdk.x86_64
2、查看JDK是否安装成功
# java -version
[root@1c164311bb8b /]# java -version openjdk version "1.8.0_222" OpenJDK Runtime Environment (build 1.8.0_222-b10) OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
3、配置环境变量
JDK默认安装路径/usr/lib/jvm
[root@1c164311bb8b jvm]# pwd /usr/lib/jvm [root@1c164311bb8b jvm]# [root@1c164311bb8b jvm]# ll total 0 drwxr-xr-x. 3 root root 17 Jul 30 05:48 java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64 lrwxrwxrwx. 1 root root 21 Jul 30 05:48 jre -> /etc/alternatives/jre lrwxrwxrwx. 1 root root 27 Jul 30 05:48 jre-1.8.0 -> /etc/alternatives/jre_1.8.0 lrwxrwxrwx. 1 root root 35 Jul 30 05:48 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk lrwxrwxrwx. 1 root root 51 Jul 30 05:48 jre-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64 -> java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64/jre lrwxrwxrwx. 1 root root 29 Jul 30 05:48 jre-openjdk -> /etc/alternatives/jre_openjdk [root@1c164311bb8b jvm]#
在/etc/profile文件添加如下命令
# set java environment JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64 PATH=$PATH:$JAVA_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME CLASSPATH PATH
保存关闭profile文件,执行如下命令生效
source /etc/profile
4、编写Dockerfile文件时,只需要定义容器变量即可(第三部可以省略)
ENV JAVA_HOME /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64
参考博客:
DOCKER 安装CENTOS,TOMCAT,JDK等相关的自定义(DOCKERFILE)镜像
CentOS 7 yum 安装与配置 JDK
https://blog.csdn.net/github_38336924/article/details/82221258