本地宿主机配置jdk
创建test目录:
[root@docker ~]# mkdir test
压缩包tomcat和jdk上传到root/test目录下:
本机部署Jdk
解压jdk:
[root@docker test]# tar -xf jdk-8u211-linux-x64.tar.gz
[root@docker test]# tar -xf apache-tomcat-8.5.35.tar.gz
[root@docker test]# ll
总用量 199844
drwxr-xr-x 9 root root 220 2月 4 14:25 apache-tomcat-8.5.35
-rw-r--r-- 1 root root 9642757 2月 4 14:23 apache-tomcat-8.5.35.tar.gz
drwxr-xr-x 7 10 143 245 4月 2 2019 jdk1.8.0_211
-rw-r--r-- 1 root root 194990602 2月 4 14:23 jdk-8u211-linux-x64.tar.gz
[root@docker test]#
移动到/user/local/jdk目录下:
[root@docker test]# mv jdk1.8.0_211 /usr/local/jdk
修改配置文件:
[root@docker local]# vi /etc/profile
#进入之后到达最低行进行粘贴下面配置
export JAVA_HOME=/usr/local/jdk
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
加载环境变量:
[root@docker local]# source /etc/profile
执行java:
[root@docker local]# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
[root@docker local]#出现1.8.8——211说明java环境已经配置完成
配置tomcat:
移动到/user/local/tomcat目录下:
[root@docker test]# mv apache-tomcat-8.5.35 /usr/local/tomcat
进入tomcat目录下:
[root@docker ~]# cd /usr/local/tomcat/
[root@docker tomcat]# ll
总用量 124
drwxr-x--- 2 root root 4096 2月 4 14:25 bin
-rw-r----- 1 root root 19539 11月 4 2018 BUILDING.txt
drwx------ 2 root root 238 11月 4 2018 conf
-rw-r----- 1 root root 6090 11月 4 2018 CONTRIBUTING.md
drwxr-x--- 2 root root 4096 2月 4 14:25 lib
-rw-r----- 1 root root 57092 11月 4 2018 LICENSE
drwxr-x--- 2 root root 6 11月 4 2018 logs
-rw-r----- 1 root root 1726 11月 4 2018 NOTICE
-rw-r----- 1 root root 3255 11月 4 2018 README.md
-rw-r----- 1 root root 7142 11月 4 2018 RELEASE-NOTES
-rw-r----- 1 root root 16262 11月 4 2018 RUNNING.txt
drwxr-x--- 2 root root 30 2月 4 14:25 temp
drwxr-x--- 7 root root 81 11月 4 2018 webapps
drwxr-x--- 2 root root 6 11月 4 2018 work
[root@docker tomcat]#
启动tomcat:
[root@docker local]# cd bin/
[root@docker bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk/jre
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
查看进程:
[root@docker bin]# ps -ef | grep tomcat
root 1699 1 3 14:46 pts/0 00:00:02 /usr/local/jdk/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 1747 1479 0 14:47 pts/0 00:00:00 grep --color=auto tomcat
[root@docker bin]#
浏览器访问tomcat网页默认8080端口:
dockerfile部署JDK
FROM centos:7
ADD jdk-8u211-linux-x64.tar.gz /usr/local
RUN mv /usr/local/jdk1.8.0_211 /usr/local/jdk
ENV JAVA_HOME=/usr/local/jdk
ENV JRE_HOME=$JAVA_HOME/jre
ENV CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
ENV PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
ADD apache-tomcat-8.5.35.tar.gz /usr/local
RUN mv /usr/local/apache-tomcat-8.5.35 /usr/local/tomcat
EXPOSE 8080
ENTRYPOINT ["/usr/local/tomcat/bin/catalina.sh","run"]
创建dockerfile文档在压缩包目录下创建:
[root@docker test]# cat dockerfile
FROM centos:7
ADD jdk-8u211-linux-x64.tar.gz /usr/local
RUN mv /usr/local/jdk1.8.0_211 /usr/local/jdk
ENV JAVA_HOME=/usr/local/jdk
ENV JRE_HOME=$JAVA_HOME/jre
ENV CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
ENV PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
ADD apache-tomcat-8.5.35.tar.gz /usr/local
RUN mv /usr/local/apache-tomcat-8.5.35 /usr/local/tomcat
EXPOSE 8080
ENTRYPOINT ["/usr/local/tomcat/bin/catalina.sh","run"]
[root@docker test]#
进行执行:
[root@docker test]# docker build -t mycentos:jdk .
开启防火墙映射80端口:
[root@docker test]# systemctl restart firewalld
[root@docker test]# docker run -itd -p 80:8080 mycentos:jdk /bin/bash
6220d56db4101a1a64094dee1fd8dde1aa9c728134a0f969c5424b1d970b0376
[root@docker test]#
进行访问80端口:
配置挂载
创建一个目录:
[root@docker test]# mkdir ROOT
[root@docker test]# cd ROOT/
[root@docker ROOT]# pwd
/root/test/ROOT
执行:
[root@docker ROOT]# docker run -itd -p 8080:8080 -v /root/test/ROOT:/usr/local/tomcat/webapps/ROOT mycentos:jdk /bin/bash df61af407921dee07f06a66c1a517822c55c9f4e7609412d95d961412c097366
创建一个网页文件:
[root@docker ROOT]# cat index.html
hello world
[root@docker ROOT]#