通过docker启动一个tomcat8.5并配置远程部署

1.在/root/下新建一个文件夹 tomcatconf
mkdir /root/tomcatconf
2.复制tomcat的配置文件
docker run --rm -v /root/tomcatconf/:/home/ tomcat cp /usr/local/tomcat/conf/tomcat-users.xml /home/
docker run --rm -v /root/tomcatconf/:/home/ tomcat cp /usr/local/tomcat/webapps/manager/META-INF/context.xml /home/
3.查看/root/tomcatconf文件夹下多了两个文件:context.xml和tomcat-users.xml
ls /root/tomcatconf
4.修改context.xml:注释掉如下内容
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
5.修改tomcat-user.xml文件。添加如下内容(配置远程访问用户):
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="123456" roles="manager-gui,admin-gui,manager-script"/>
6.启动tomcat
 docker run -p 8888:8080 -v /root/tomcatconf/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml -v /root/tomcatconf/context.xml:/usr/local/tomcat/webapps/manager/META-INF/context.xml -d tomcat
7.访问docker宿主机的http://ip:8888/manager/html,提示输入密码。输入tomcat/123456(在第五步中配置)。出现如下界面即为配置成功

Author: jxin