使用Dockerfile构建tomcat-docker镜像

vim Dockerfile

OS环境配置

RUN yum install -y wget

安装JDK

RUN mkdir /opt/jdk
COPY jdk-8u172-linux-x64.tar.gz /opt/jdk

RUN tar xzf /opt/jdk/jdk-8u172-linux-x64.tar.gz -C /opt/jdk && rm -rf /opt/jdk/jdk-8u172-linux-x64.tar.gz

安装tomcat

RUN mkdir /opt/tomcat
RUN wget -P /opt/tomcat http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.8/bin/apache-tomcat-9.0.8.tar.gz
RUN tar xzf /opt/tomcat/apache-tomcat-9.0.8.tar.gz -C /opt/tomcat && rm -rf /opt/tomcat/apache-tomcat-9.0.8.tar.gz

设置环境变量

ENV JAVA_HOME /opt/jdk/jdk1.8.0_172

ENV CATALINA_HOME /opt/apache-tomcat-9.0.8

ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin

开启内部服务端口

EXPOSE 8080

启动tomcat服务器

ENTRYPOINT /opt/tomcat/apache-tomcat-9.0.8/bin/startup.sh && tail -F /opt/tomcat/apache-tomcat-9.0.8/logs/catalina.out

推荐阅读更多精彩内容