群晖nas docker 挂载tomcat目录

发布时间 2023-07-20 21:58:24作者: 啄木鸟伍迪

前情

使用场景描述:

docker 安装了tomcat,想要通过tomcat部署war包,但是无法上次war包到容器,于是使用了挂载;

docker容器目录挂载 :

我们可以在创建容器的时候,将宿主机的目录与容器内的目录进行映射,这样我们就可以实现宿主机和容器目录的双向数据自动同步;

 

tomcat 安装和挂载目录

1.查找/下载tomcat 

docker pull billygoo/tomcat8-jdk8

2.启动tomcat

docker run -d -p 8080:8080 --name tomcat8 billygoo/tomcat8-jdk8:latest

 

3.复制tomcat8容器中tomcat目录 到nas 本地目录/docker/tomcat

docker cp tomcat8:/usr/local/tomcat /volume1/docker/tomcat

 

 

4.挂载目录

docker run --name tomcat -p 8088:8080 -v /volume1/docker/tomcat/tomcat:/usr/local/tomcat/  billygoo/tomcat8-jdk8:latest

5.更改tomcat用户(tomcat-users.xml),添加一个用户:

例如:

<user username="tomcat" password="tomcat" roles="manager-gui" />

完整文件如下:

 1 <?xml version='1.0' encoding='utf-8'?>
 2 <!--
 3   Licensed to the Apache Software Foundation (ASF) under one or more
 4   contributor license agreements.  See the NOTICE file distributed with
 5   this work for additional information regarding copyright ownership.
 6   The ASF licenses this file to You under the Apache License, Version 2.0
 7   (the "License"); you may not use this file except in compliance with
 8   the License.  You may obtain a copy of the License at
 9 
10       http://www.apache.org/licenses/LICENSE-2.0
11 
12   Unless required by applicable law or agreed to in writing, software
13   distributed under the License is distributed on an "AS IS" BASIS,
14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   See the License for the specific language governing permissions and
16   limitations under the License.
17 -->
18 <tomcat-users xmlns="http://tomcat.apache.org/xml"
19               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20               xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
21               version="1.0">
22 <!--
23   NOTE:  By default, no user is included in the "manager-gui" role required
24   to operate the "/manager/html" web application.  If you wish to use this app,
25   you must define such a user - the username and password are arbitrary. It is
26   strongly recommended that you do NOT use one of the users in the commented out
27   section below since they are intended for use with the examples web
28   application.
29 -->
30 <user username="tomcat" password="tomcat" roles="manager-gui" />
31 <!--
32   NOTE:  The sample user and role entries below are intended for use with the
33   examples web application. They are wrapped in a comment and thus are ignored
34   when reading this file. If you wish to configure these users for use with the
35   examples web application, do not forget to remove the <!.. ..> that surrounds
36   them. You will also need to set the passwords to something appropriate.
37 -->
38 <!--
39   <role rolename="tomcat"/>
40   <role rolename="role1"/>
41   <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
42   <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
43   <user username="role1" password="<must-be-changed>" roles="role1"/>
44 -->
45 </tomcat-users>
View Code

 

6.修改server.xml配置:/docker/tomcat/tomcat/conf下的server.xml

找到<Host> 添加一条context   

<Context path="/muses" docBase="ssm-demo-mgt" reloadable="true" />
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
          <Context path="/muses" docBase="ssm-demo-mgt" reloadable="true" />
        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>

 

7.上传war包到webapps目录下,并且重启tomcat  

重启指令:

docker restart tomcat

 

8.登入http://192.168.1.120:8088/manager/html 用户名密码就是刚刚设置的;tomcat  tomcat;

 9.访问war包:http://192.168.1.120:8088/muses/login