1.下載jdk8 好比nacos會引用此變量java
安裝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
配置環境變量:linux
在 /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/bindocker
執行下面命令使設置生效
source /etc/profileapache
下載tomcat8 暫不用centos
wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.23/bin/apache-tomcat-8.0.23.tar.gz
2.建立dockerfile文件tomcat
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鏡像bash
[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的文件 jvm
-t 指定鏡像的名稱和tagui
4.運行建立的鏡像spa
[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