1.下载jdk8 比如nacos会引用此变量
安装1.8.0的所有文件
yum install java-1.8.0-openjdk* -y
使用命令检查是否安装成功
java -version
jdk自动安装目录为:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64
配置环境变量:
在 /etc/profile 文件中加入如下内容:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64
export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin
执行下面命令使设置生效
source /etc/profile
下载tomcat8 暂不用
wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.23/bin/apache-tomcat-8.0.23.tar.gz
2.创建dockerfile文件
FROM centos:latest #使用ADD指令会直接对jdk-8u141-linux-x64.tar.gz进行解压 不用单独的tar解压 ADD jdk-8u141-linux-x64.tar.gz /usr/local/ ENV JAVA_HOME /usr/local/jdk1.8.0_141 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV PATH $PATH:$JAVA_HOME/bin
3.用dockerfile文件创建jdk镜像
[root@insure jdk8]# docker build -t jdk-8u141:20181222 . -f dockerfile Sending build context to Docker daemon 185.5MB Step 1/5 : FROM centos:latest ---> 1e1148e4cc2c Step 2/5 : ADD jdk-8u141-linux-x64.tar.gz /usr/local/ ---> 65475cb92b9e Step 3/5 : ENV JAVA_HOME /usr/local/jdk1.8.0_141 ---> Running in 4537fa128bf8 Removing intermediate container 4537fa128bf8 ---> a5ec3ad7eefd Step 4/5 : ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ---> Running in 170040d357ac Removing intermediate container 170040d357ac ---> 70417d2b9cad Step 5/5 : ENV PATH $PATH:$JAVA_HOME/bin ---> Running in eacfe0487c6a Removing intermediate container eacfe0487c6a ---> c717428b1276 Successfully built c717428b1276 Successfully tagged jdk-8u141:20181222 [root@insure jdk8]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE jdk-8u141 20181222 c717428b1276 18 seconds ago 578MB centos latest 1e1148e4cc2c 2 weeks ago 202MB openjdk latest 8e7eacedab93 2 weeks ago 986MB
命令说明:使用-f 指定要使用的dockerfile,如果不指定会寻找当前目录名为dockerfile的文件
-t 指定镜像的名称和tag
4.运行创建的镜像
[root@insure jdk8]# docker run -d -it jdk-8u141:20181222 /bin/bash 14c0f65b236c89c84723fe9e3f7011e405f388bf443608f054aaf24d5c290882 [root@insure jdk8]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 14c0f65b236c jdk-8u141:20181222 "/bin/bash" 5 seconds ago Up 4 seconds vigorous_yonath