docker run --privileged -it --name java --restart=always -p 8080:8080 centos:7.4.1708 /usr/sbin/init
安装jdk
[root@lvhanzhi ~]# ls jdk-8u121-linux-x64.tar.gz
jdk-8u121-linux-x64.tar.gz
[root@lvhanzhi ~]# docker cp jdk-8u121-linux-x64.tar.gz java:/root
[root@lvhanzhi ~]# docker exec -it java /bin/bash
[root@96534033bdea /]# cd /root
[root@96534033bdea ~]# ls /root/jdk-8u121-linux-x64.tar.gz
[root@96534033bdea ~]# tar xf jdk-8u121-linux-x64.tar.gz
[root@96534033bdea ~]# mv jdk1.8.0_121/ /usr/local/jdk1.8
[root@96534033bdea ~]# ln -s /usr/local/jdk1.8 /usr/local/jdk #做软链接(方便日后升级)
[root@96534033bdea ~]# vi /etc/profile.d/jdk1.8.sh
export JAVA_HOME=/usr/local/jdk1.8
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
[root@96534033bdea ~]# source /etc/profile
[root@96534033bdea ~]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
安装tomcat
[root@lvhanzhi ~]# docker cp apache-tomcat-8.0.38.tar.gz java:/root
[root@96534033bdea ~]# ls apache-tomcat-8.0.38.tar.gz
[root@96534033bdea ~]# tar xf apache-tomcat-8.0.38.tar.gz
[root@96534033bdea ~]# mv apache-tomcat-8.0.38 /usr/local/tomcat-8.0.38
[root@96534033bdea ~]# ln -s /usr/local/tomcat-8.0.38 /usr/local/tomcat
[root@96534033bdea ~]# cd /usr/local/tomcat/webapps #进入工作目录(把没编译的代码放进去)