一、创建目录
mkdir /haolb/mydockerfile/tomcat8
二、将jdk和tomcat安装的压缩包拷贝进上一步目录
三、在/haolb/mydockerfile/tomcat8目录下新建Dockerfile文件
FROM centos:centos7
MAINTAINER haolb<haolb@qq.com>
#把宿主机当前上下文的c.txt拷贝到容器/usr/local/路径下
COPY c.txt /usr/local/cincontainer.txt
#把java与tomcat添加到容器中
ADD jdk-8u281-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-8.5.65.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_281
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.65
ENV CATALINA_BASE /usr/local/apache-tomcat-8.5.65
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
#容器运行时监听的端口
EXPOSE 8080
#启动时运行tomcat
# ENTRYPOINT ["/usr/local/apache-tomcat-8.5.65/bin/startup.sh" ]
# CMD ["/usr/local/apache-tomcat-8.5.65/bin/catalina.sh","run"]
CMD /usr/local/apache-tomcat-8.5.65/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.65/bin/logs/catalina.out
四、构建
docker build -f ./TomcatDockerfile -t haolbtomcat8 .
五、运行
docker run -d -p 9080:8080 --name mytomcat8 -v /haolb/mydockerfile/tomcat8/webapps:/usr/local/apache-tomcat-8.5.65/webapps -v /haolb/mydockerfile/tomcat8/tomcat8logs/:/usr/local/apache-tomcat-8.5.65/logs --privileged=true haolbtomcat8
六、验证