Docker learning notes [10 docker application - deploy TOMCAT service

Select base image

The base image uses the latest version of tomcat8 alpine officially provided by dokcer hub, https://hub.docker.com/_/tomcat/

docker pull tomcat:8.5.32-jre8-alpine
docker tag tomcat:8.5.32-jre8-alpine 10.240.4.159/app/tomcat:8.5.32-alpine
docker push 10.240.4.159/app/tomcat:8.5.32-alpine

 

Add SSH support

# Execute on host
mkdir -p /root/docker_build/tomcat-ssh
cd /root/docker_build/tomcat-ssh
cp /usr/share/zoneinfo/Asia/Shanghai .

vi repositories
#------------------------------------------------------------------------
http://mirrors.aliyun.com/alpine/v3.7/main
http://mirrors.aliyun.com/alpine/v3.7/community
#------------------------------------------------------------------------

vi run.sh
#------------------------------------------------------------------------
#!/bin/bash
/usr/sbin/sshd -D &
exec mysqld
#------------------------------------------------------------------------

vi Dockerfile
#------------------------------------------------------------------------
FROM 10.240.4.159/app/tomcat:8.5.32-alpine
ADD Shanghai /etc/localtime
ADD repositories /etc/apk/repositories
RUN apk --no-cache update
RUN apk --no-cache add openssh
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" \
    && ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N "" \
    && ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N "" \
    && ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" \
    && sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config \
    && echo 'root:ydgw.cn' | chpasswd 
ADD run.sh /root/run.sh
RUN chmod +x /root/run.sh
VOLUME ["/usr/local/tomcat/webapps", "/usr/local/tomcat/conf", "/usr/local/tomcat/logs"]
CMD ["/root/run.sh"]
#------------------------------------------------------------------------

docker build -t 10.240.4.159/app/tomcat:8.5.32-alpine-ssh .
docker push 10.240.4.159/app/tomcat:8.5.32-alpine-ssh


# The following is to set a safe root password for a specific project, and build a separate image for later use (put it in a new folder)
vi Dockerfile
#------------------------------------------------------------------------
FROM 10.240.4.159/app/tomcat:8.5.32-alpine-ssh
RUN echo 'root:xxxxxxxxxx' | chpasswd
#------------------------------------------------------------------------

docker build -t 10.240.4.159/erpjs/tomcat:8.5.32-alpine-ssh-erpjs .
docker push 10.240.4.159/erpjs/tomcat:8.5.32-alpine-ssh-erpjs

 


Create VOLUME volume

# Execute on host
mkdir /docker_mnt/erpjs-tomcat

# Download apache-tomcat-8.5.32.tar.gz and upload it to the current / tmp directory
cd /tmp
tar zxvpf apache-tomcat-8.5.32.tar.gz
cd apache-tomcat-8.5.32
cp -rf webapps /docker_mnt/erpjs-tomcat/
cp -rf conf /docker_mnt/erpjs-tomcat/
cp -rf logs /docker_mnt/erpjs-tomcat/

 

Deploy TOMCAT service

  1. Log in to Rancher(1.6.18), and the choreographer uses the default Cattle
  2. Application user add application name: [ERP-JS] - create
  3. Add service - add the following information to the add service page - create
    Name: tomcat
    Select image: 10.240.4.159/erpjs/tomcat:8.5.32-alpine-ssh-erpjs
    Port mapping: 8080:8080 / TCP 15922:22 / TCP
    
    Volume - add volume: / docker_mnt / erpjs Tomcat / webapps: / usr / local / Tomcat / webapps
                 /docker_mnt/erpjs-tomcat/conf:/usr/local/tomcat/conf
                 /docker_mnt/erpjs-tomcat/logs:/usr/local/tomcat/logs
    
    Network host name: erpjs
    
    Scheduling - run all containers on the specified host: docker159
    

     

Configure manager GUI

# SSH login tomcat container
vi /usr/local/tomcat/conf/tomcat-users.xml
# stay</tomcat-users>  Add above
#------------------------------------------------------------------------
<role rolename="admin-gui"/>                                                   
<role rolename="admin-script"/>                                          
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="ydgw.cn18" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
#------------------------------------------------------------------------

# Establish
vi /usr/local/tomcat/conf/Catalina/localhost/manager.xml
#------------------------------------------------------------------------
<Context privileged="true" antiResourceLocking="false"
         docBase="${catalina.home}/webapps/manager">
    <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>
#------------------------------------------------------------------------

# Note out the original content and change it to the following
vi /usr/local/tomcat/webapps/host-manager/META-INF/context.xml
#------------------------------------------------------------------------
<!--<Context antiResourceLocking="false" privileged="true" >                                                                            
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"                                                                         
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />                                                                              
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>-->                                                                                                                           
<Context antiResourceLocking="false" privileged="true" >                                                                                
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"                                                                         
         allow="^.*$" />                                                                                                                
</Context>                       
#------------------------------------------------------------------------

# If you only modify the first two items, you will see that you can access the service status and Manager APP, but not the HostManager

 

Reference resources

Tags: PHP Tomcat ssh Docker Apache

Posted on Sat, 02 Nov 2019 00:57:39 -0700 by julzk