touch Dockerfile
在Dockerfile中输入以下内容
FROM centos
MAINTAINER Irish<3395327965@qq.com>
#把宿主机当前上下文的c.txt拷贝到/usr/local路径下
COPY c.txt /usr/local/cincontainer.txt
#把java和tomocat添加到容器中
ADD jdk-8u152-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-9.0.20.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_152
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.20
ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.20
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
#容器运行时监听的端口
EXPOSE 8080
#启动时运行tomcat
CMD /usr/local/apache-tomcat-9.0.20/bin/startup.sh && tail -f /usr/local/apache-tomcat-9.0.20/logs/catalina.out
构建生成镜像
docker build -t irishtomcat9 .
通过镜像启动容器
docker run -d -p 9999:8080 --name mytomcat9 -v /usr/local/mytomcat9/test:/usr/local/apache-tomcat-9.0.20/webapps/test -v /usr/local/mytomcat9/tomcat9logs://usr/local/apache-tomcat-9.0.20/logs irishtomcat9
可以将web工程拷贝到/usr/local/mytomcat9/test目录下,再重新启动容器,就可以访问web工程了