dockerfile实现tomcat以及java的war包自动部署

1. 下载jdk和tomcat

wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.93/bin/apache-tomcat-8.5.93.tar.gz
wget https://repo.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gz

2. vim Dockerfile

FROM centos:latest     
MAINTAINER Amadeus
# now add java and tomcat support in the container
ADD jdk-8u202-linux-x64.tar.gz /usr/local/                  
ADD apache-tomcat-8.5.93.tar.gz /usr/local/

# configuration of java and tomcat ENV
ENV JAVA_HOME /usr/local/jdk1.8.0_202
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.93
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin

# container listener port
EXPOSE 8080
# startup web application services by self
CMD /usr/local/apache-tomcat-8.5.93/bin/catalina.sh run

3. build docker镜像

docker build -t ureport2 .

4. docker run ,映射本地war包路径和logs日志

docker run --name ureport -d -p 8080:8080 -v /home/ureport/logs:/usr/local/apache-tomcat-8.5.93/logs -v /home/ureport/www:/usr/local/apache-tomcat-8.5.93/webapps --privileged=true ureport2

5. 关闭防火墙

service firewalld stop

6. 如果出现docker network错误,执行:

​systemctl restart docker

posted @ 2024-01-08 14:45  李济宏(Amadeus)  阅读(193)  评论(0编辑  收藏  举报