docker基于ubuntu镜像自动化部署war

环境

docker:Docker version 17.11.0-ce
ubuntu: 14.04
java: 8
tomcat: 7

docker化,并上传至harbor

  1. Dockerfile

     FROM ubuntu:14.04
    
     MAINTAINER    xiaojie
     
     ADD jdk-8u71-linux-x64.tar.gz /usr/local/
     
     ADD apache-tomcat-7.0.70.tar.gz  /usr/local/
     
     ADD  tomcat-users.xml /usr/local/apache-tomcat-7.0.70/conf/
     
     ADD  settings.xml /usr/local/apache-tomcat-7.0.70/conf/
     
     ADD  demo.war /usr/local/apache-tomcat-7.0.70/webapps/
     
     ENV JAVA_HOME /usr/local/jdk1.8.0_71
     
     ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
     
     ENV CATALINA_HOME /usr/local/apache-tomcat-7.0.70
     
     ENV CATALINA_BASE /usr/local/apache-tomcat-7.0.70
     
     ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
     
     EXPOSE 8080
     
     ENTRYPOINT ["/usr/local/apache-tomcat-7.0.70/bin/catalina.sh", "run" ]
    
  2. tomcat-users.xml

<?xml version='1.0' encoding='utf-8'?>

  <tomcat-users>
    <role rolename="manager-gui"/>
     <role rolename="manager-script"/>
        <user username="demo" password="demo11111"                                   roles="manager-gui,manager-script"/>
    </tomcat-users> 
  1. settings.xml
    <?xml version="1.0"encoding="UTF-8"?>
<settings>
<servers>
    <server>
        <id>TomcatServer</id>
        <username>demo</username>
        <password> demo11111</password>
    </server>
</servers>
</settings>
  1. build, run

     docker stop demo-container
     docker rm demo-container
     docker build -t demo/tomcat .
     docker run --name demo-container -d -p 8080:8080 demo/tomcat  
    
  2. push之前需要将harbor地址加入到信任中,vi /etc/default/docker

    DOCKER_OPTS=”$DOCKER_OPTS –insecure-registry ...:8888″

  3. push至私有harbor库

     docker login -u demo -p password123   **.**.**.**:8888
     docker tag demo/tomcat **.**.**.**:8888/demo/tomcat
     docker push **.**.**.**:8888/demo/tomcat
    

坑点

  1. 保持tomcat版本、java版本和开发环境一样,不然可能会有莫名的问题
    原文作者:十六郎
    原文地址: https://www.jianshu.com/p/4ad42d46d16d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞