docker自定义tomcat访问jsp页面
李羽秋
2022年01月26日 · 阅读 1,066
docker自定义tomcat访问jsp页面
1.创建tomcat所在文件夹
mkdir -p /liyuqiu/mydockerfile/tomcat9
2.在上述目录下touch.txt
3.将jdk和tomcat 安装的压缩包拷贝至进上一步目录
4.在/liyuqiu/dockerfile/tomcat9 目录下新建Docker文件,内容如下
FROM centos
MAINTAINER LIYUQIU<510336979@qq.com>
#把宿主机当前上下文的c.txt拷贝到容器/usr/local路径下
COPY c.txt /usr/local/cincontainer.txt
#把java和tomcat添加到容器中
ADD jdk-8u261-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-8.5.59.tar.gz /usr/local/
#安装vim编辑器
RUN yum -y install vim
#设置工作访问时候的WORKDIR路径,登录落脚点
ENV MYPATH /usr/local
WORKDIR $MYPATH
#配置java与tomcat环境变量
ENV JAVA_HOME /usr/local/jdk1.8.0_261
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.59
ENV CATALINA_BASE /usr/local/apache-tomcat-8.5.59
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
#容器运行时监听的端口
EXPOSE 8080
#启动时运行tomcat
#ENTRYPOINT ["/usr/local/apache-tomcat-8.5.59/bin/startup.sh"]
#CMD ["/usr/local/apache-tomcat-8.5.59/bin/catalina.sh","run"]
CMD /usr/local/apache-tomcat-8.5.59/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.59/bin/logs/catalina.out
5.构建
docker build -t litomcat9 .
6.run
docker run -d -p 9080:8080 --name mytomcatcontainer -v /mydocker/tomcat9/test:/usr/local/apache-tomcat-9.0.45/webapps/test -v /mydocker/tomcat9/logs/:/usr/local/apache-tomcat-9.0.45/logs --privileged=true litomcat9.
7.test目录下新建文本web.xml和a.jsp
vim web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>test</display-name>
</web-app>
vim a.jsp
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>test</display-name>
8.查看容器id
docker ps
9.重启容器
docker restart 926e87cd8715
10.结果如下
分类:
Docker
标签:
无
本文作者:李羽秋