准备jdk和tomcat压缩包
编写Dockerfile文件
#基于centos镜像来构建 FROM centos MAINTAINER quan<[email protected]> #将宿主机下的文本拷贝到容器/usr/local/路径下 COPY cp.txt /usr/local/cpContainer.txt #把jdk和Tomcat添加到容器中 ADD jdk-8u181-linux-x64.tar.gz /usr/local/ ADD apache-tomcat-9.0.30.tar.gz /usr/local/ #设置登录落脚点,进入工作目录 ENV MYPATH /usr/local WORKDIR $MYPATH #配置jdk和tomcat环境变量 ENV JAVA_HOME /usr/local/jdk1.8.0_181 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.30 ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.30 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin #运行容器的监听端口 EXPOSE 8080 #指定容器启动时默认的执行命令 CMD /usr/local/apache-tomcat-9.0.30/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.30/bin/logs/catalina.out
构建镜像
docker build -t mytomcat9 .
run 新构建的tomcat镜像
docker run -d -p 9000:8080 --name shutomcat9 -v /shuquan/myproject/tomcat9/test:/usr/local/apache-tomcat-9.0.30/webapps/test -v /shuquan/myproject/tomcat9/tomcat9logs/:/usr/local/apache-tomcat-9.0.30/logs --privileged=true mytomcat9
测试
原文地址:https://www.cnblogs.com/Lambquan/p/12153660.html
时间: 2024-11-06 09:37:52