使用Dockerfile搭建NGINX+TOMCAT

NGINX

1、nginx.conf里主要配置信息

        location /xiaofei{
            root html;
            index  index.html index.htm;
            proxy_pass     http://lnmp_tomcat:8080/xiaofei;
            proxy_set_header   Host    $host;
            proxy_set_header   Remote_Addr    $remote_addr;
            proxy_set_header   X-Real-IP    $remote_addr;
            proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;

        }

2、Dockerfile内容

FROM docker.io/centos
LABEL "auth"="Uncle.joker" \
      "mail"="[email protected]"
ENV TIME_ZOME Asia/Shanghai
RUN yum install -y gcc gcc-c++ make openssl-devel prce-devel
ADD nginx-1.14.2.tar.gz /opt/
RUN cd /opt/nginx-1.14.2 && \
    ./configure --prefix=/usr/local/nginx && \
    make -j 4 && \
    make install

RUN rm -rf /opt/nginx* && \
    yum clean all && \
    echo "${TIME_ZOME}" > /etc/timezone && \
    ln -sf /usr/share/zoneinfo/${TIME_ZOME} /etc/localtime

COPY nginx.conf /usr/local/nginx/conf/
WORKDIR /usr/local/nginx/
EXPOSE 80
CMD ["./sbin/nginx","-g","daemon off;"]

3、Duild镜像

# cd /root/dockerfile/nginx && docker build -t mytomcat/nginx:1.5 .

4、启动镜像

# docker run -itd --name nginx1 --network lnmp -p 8888:80 mytomcat/nginx:1.5

TOMCAT

1、目录结构如下

[root@ecs-5704-0004 tomcat]# tree ./
./
├── apache-tomcat-7.0.92.tar.gz
├── catalina.sh
├── Dockerfile
├── jdk-7u80-linux-x64.tar.gz
└── server.xml

2、配置文件内容
(1)、server.xml



  
  
  
  
  
  

  

    
  

  

    
    

    

      

        
      

      
                 

        

      
    
  

(2)、catalina.sh配置内容如下
主要是在启动脚本的内容下增加了内存等信息的调优。

JAVA_OPTS="-server -Xms6G -Xmx6G  -Xmn2248M -XX:PermSize=384M -XX:MaxPermSize=700M -Xss256K -XX:+DisableExplicitGC -XX:SurvivorRa
tio=4 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBef
oreCompaction=0 -XX:+CMSClassUnloadingEnabled -XX:LargePageSizeInBytes=128M -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccu
pancyOnly -XX:CMSInitiatingOccupancyFraction=80 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+PrintClassHistogram -XX:+PrintGCDetails  -XX:+
PrintGCDateStamps  -XX:+PrintHeapAtGC  -verbose:gc -Xloggc:$CATALINA_BASE/logs/gc.log "

3、Dockerfile里的内容

FROM docker.io/centos
LABEL "auth"="Uncle.Joker" \
      "mail"="[email protected]"

ENV TIME_ZOME Asia/Shanghai

#--config JDK.1.7
ADD jdk-7u80-linux-x64.tar.gz /opt/
ENV JAVA_HOME /opt/jdk1.7.0_80
ENV PATH ${JAVA_HOME}/bin:${PATH}

#--config TOMCAT 7
ADD apache-tomcat-7.0.92.tar.gz /usr/local/
RUN mv /usr/local/apache-tomcat-7.0.92 /usr/local/tomcat
COPY server.xml /usr/local/tomcat/conf/
COPY catalina.sh /usr/local/tomcat/bin/
RUN chmod +x /usr/local/tomcat/bin/catalina.sh
WORKDIR /usr/local/tomcat
EXPOSE 8080
CMD ["./bin/catalina.sh","run"]

4、Build镜像

# /root/dockerfile/tomcat && docker build -t mytomcat:7.0.92_latest .

5、启动镜像

# docker run -itd --name lnmp_tomcat --network lnmp  -v /root/dockerfile/app/tomcat/:/data/apps/fireway mytomcat:7.0.92_latest

转载于:https://blog.51cto.com/7834466/2341398

你可能感兴趣的:(使用Dockerfile搭建NGINX+TOMCAT)