Docker中部署tomcat,并开启远程管理

我们可以自己把tomcat加到docker容器中,也可以用现成的仓库中tomcat。我们就用现成的了,然后改下配置

[root@localhost dockerfile]# docker search tomcat
INDEX       NAME                                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/tomcat                                Apache Tomcat is an open source implementa...   1925      [OK]       
docker.io   docker.io/tomee                                 Apache TomEE is an all-Apache Java EE cert...   51        [OK]       
docker.io   docker.io/dordoka/tomcat                        Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 ba...   49                   [OK]
docker.io   docker.io/davidcaste/alpine-tomcat              Apache Tomcat 7/8 using Oracle Java 7/8 wi...   26                   [OK]
docker.io   docker.io/bitnami/tomcat                        Bitnami Tomcat Docker Image                     17                   [OK]
docker.io   docker.io/consol/tomcat-7.0                     Tomcat 7.0.57, 8080, "admin/admin"              16                   [OK]
docker.io   docker.io/cloudesire/tomcat                     Tomcat server, 6/7/8                            15                   [OK]
docker.io   docker.io/tutum/tomcat                          Base docker image to run a Tomcat applicat...   10                   
docker.io   docker.io/meirwa/spring-boot-tomcat-mysql-app   a sample spring-boot app using tomcat and ...   9                    [OK]
docker.io   docker.io/jeanblanchard/tomcat                  Minimal Docker image with Apache Tomcat         8                    
docker.io   docker.io/aallam/tomcat-mysql                   Debian, Oracle JDK, Tomcat & MySQL              7                    [OK]
docker.io   docker.io/rightctrl/tomcat                      CentOS , Oracle Java, tomcat application s...   3                    [OK]
docker.io   docker.io/amd64/tomcat                          Apache Tomcat is an open source implementa...   2                    
docker.io   docker.io/arm64v8/tomcat                        Apache Tomcat is an open source implementa...   2                    
docker.io   docker.io/fabric8/tomcat-8                      Fabric8 Tomcat 8 Image                          2                    [OK]
docker.io   docker.io/maluuba/tomcat7-java8                 Tomcat7 with java8.                             2                    
docker.io   docker.io/99taxis/tomcat7                       Tomcat7                                         1                    [OK]
docker.io   docker.io/camptocamp/tomcat-logback             Docker image for tomcat with logback integ...   1                    [OK]
docker.io   docker.io/primetoninc/tomcat                    Apache tomcat 8.5, 8.0, 7.0                     1                    [OK]
docker.io   docker.io/jelastic/tomcat                                                                       0                    
docker.io   docker.io/oobsri/tomcat8                        Testing CI Jobs with different names.           0                    
docker.io   docker.io/picoded/tomcat7                       tomcat7 with jre8 and MANAGER_USER / MANAG...   0                    [OK]
docker.io   docker.io/s390x/tomcat                          Apache Tomcat is an open source implementa...   0                    
docker.io   docker.io/swisstopo/service-print-tomcat        backend tomcat for service-print "the true...   0                    
docker.io   docker.io/trollin/tomcat                                                                        0                    
[root@localhost dockerfile]# 

我的目的:添加tomcat用户,开启manager管理

新建manager.xml文件:

[root@localhost dockerfile]# cat manager.xml 
<Context privileged="true" antiResourceLocking="false"   
         docBase="${catalina.home}/webapps/manager">  
             <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />  
</Context> 

新建tomcat-users.xml文件

[root@localhost dockerfile]# cat tomcat-users.xml 
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary. It is
  strongly recommended that you do NOT use one of the users in the commented out
  section below since they are intended for use with the examples web
  application.
-->
<!--
  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->

  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <user username="tomcat" password="xuhaixing" roles="manager-gui,manager-script"/>
</tomcat-users>

新建Dockerfile

[root@localhost dockerfile]# cat Dockerfile 
FROM tomcat
MAINTAINER "xuhaixing<[email protected]>"
ADD tomcat-users.xml /usr/local/tomcat/conf
ADD manager.xml /usr/local/tomcat/conf/Catalina/localhost/manager.xml
执行
[xuhaixing@localhost dockerfile]$ docker build -t xuhaixing/tomcat1 ./
Sending build context to Docker daemon 5.632 kB
Step 1/4 : FROM tomcat
 ---> 2d084b11164d
Step 2/4 : MAINTAINER "xuhaixing<[email protected]>"
 ---> Using cache
 ---> 6c239147ded7
Step 3/4 : ADD tomcat-users.xml /usr/local/tomcat/conf
 ---> Using cache
 ---> 0c60204d7f65
Step 4/4 : ADD manager.xml /usr/local/tomcat/conf/Catalina/localhost/manager.xml
 ---> Using cache
 ---> 6d7dbd520df7
Successfully built 6d7dbd520df7

然后执行

docker run -d -p 9091:8080 -v /usr/local/tomcat/webapps --name managertomcat xuhaixing/tomcat1

tomcat就启动了,访问一下






猜你喜欢

转载自blog.csdn.net/u012326462/article/details/81041246