Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Tomcat users configuration not working

Update: cleanup and directly indicate the problem and the solution.

PROBLEM:

Docker-tomcat was properly installed and running, except for the 403 Access error in the Manager App. It also seems that my docker tomcat cannot find my tomcat-users.xml configuration.

SOLUTION

Thanks to Farhad and Sanket for the answers.

[Files]:

Dockerfile

FROM tomcat:8.5.11
MAINTAINER Borgy Manotoy <[email protected]>

# Update Apt and then install Nano editor (RUN can be removed)
RUN apt-get update && apt-get install -y \
    nano \
&& mkdir -p /usr/local/tomcat/conf

# Copy configurations (Tomcat users, Manager app)
COPY tomcat-users.xml /usr/local/tomcat/conf/
COPY context.xml /usr/local/tomcat/webapps/manager/META-INF/

Tomcat Users Configuration (conf/tomcat-users.xml)

<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">
    <role rolename="manager-gui"/>
    <role rolename="manager-script"/>
    <user username="admin" password="password" roles="manager-gui,manager-script" />
</tomcat-users>

Application Context (webapps/manager/META-INF/context.xml)

<?xml version="1.0" encoding="UTF-8"?>
<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" />
  -->
</Context>

[STEPS & COMMANDS]:

  1. Build Docker Image

    docker build -t borgymanotoy/my-tomcat-docker .

  2. Run Image (my-tomcat-docker and set port to 8088)

    docker run --name my-tomcat-docker-container -p 8088:8080 -it -d borgymanotoy/my-tomcat-docker

  3. Go to the container's bash (to check files inside the container thru bash)

    docker exec -it biyahe-tomcat-docker-container bash

like image 522
Borgy Manotoy Avatar asked Mar 09 '17 10:03

Borgy Manotoy


People also ask

What is Tomcat users XML?

It is a simple XML file; the root element is tomcat-users and the only allowed child elements are role and user . Each role element has one attribute called rolename , and each user element has three attributes: name , password , and roles . The default tomcat-users. xml file contains the XML listed in Example 7-3.

How do I start Tomcat in debug mode in Docker?

Open the run/debug configuration window. Then click + and select remote. Now add the host and JPDA port and click apply. Finally click the debug icon then you will be able to debug you application.


1 Answers

First you need to expose your application in the container, so you can connect to it from dockerhost/network.

docker run -d -p 8000:8080 tomcat:8.5.11-jre8

You need to change 2 files in order to access the mangaer app from remote host. (Browser on Docker host is considered remote, only packets received on containers loopback are considered local for tomcat)

  1. /usr/local/tomcat/webapps/manager/META-INF/context.xml Note the commented section.

    <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" />
    -->
    

Please note the commented section.

  1. /usr/local/tomcat/conf/tomcat-users.xml as you stated in the question.

    <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">
    <role rolename="manager-gui"/>
    <role rolename="manager-script"/>
    <user username="admin" password="password" roles="manager-gui,manager-script" />
    

In order to make changes to files in the container, You can try building your own image, but I suggest using docker volumes or bind mounts.

Also make sure you restart the container so the changes take effect.

like image 167
Farhad Farahi Avatar answered Oct 13 '22 23:10

Farhad Farahi