2017年04月01日 14:52:36 閱讀數:9134 標籤: tomcatdocker 更多java
我的分類: Dockerlinux
# 版本信息 FROM centos MAINTAINER locutus "locutus@foxmail.com" # OS環境配置 RUN yum install -y wget # 安裝JDK RUN mkdir /var/tmp/jdk RUN wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" -P /var/tmp/jdk http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz RUN tar xzf /var/tmp/jdk/jdk-8u111-linux-x64.tar.gz -C /var/tmp/jdk && rm -rf /var/tmp/jdk/jdk-8u111-linux-x64.tar.gz # 安裝tomcat RUN mkdir /var/tmp/tomcat RUN wget -P /var/tmp/tomcat http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.8/bin/apache-tomcat-8.5.8.tar.gz RUN tar xzf /var/tmp/tomcat/apache-tomcat-8.5.8.tar.gz -C /var/tmp/tomcat && rm -rf /var/tmp/tomcat/apache-tomcat-8.5.8.tar.gz #設置環境變量 ENV JAVA_HOME /var/tmp/jdk/jdk1.8.0_111 ENV CATALINA_HOME /var/tmp/tomcat/apache-tomcat-8.5.8 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin #打包項目並拷貝到tomcat webapps目錄 RUN mkdir /var/tmp/webapp ADD ./ /var/tmp/webapp RUN cd /var/tmp/webapp && cp /var/tmp/webapp/war/sm_new.war /var/tmp/tomcat/apache-tomcat-8.5.8/webapps/ #開啓內部服務端口 EXPOSE 8080 #啓動tomcat服務器 CMD ["./var/tmp/tomcat/apache-tomcat-8.5.8/bin/catalina.sh","run"] && tail -f /var/tmp/tomcat/apache-tomcat-8.5.8/logs/catalina.out
# docker build -t tomcat .
. 表示Dockerfile在當前文件夾下,也可以使用絕對路徑(/path/to/Dockerfile)來表示web
# docker run -it -p 12345:8080 --name=tomcat-test tomcat
而後在命令行鍵入 Ctrl + p , Ctrl + q,使容器在後臺運行docker