Skip to content

Instantly share code, notes, and snippets.

@mcasperson
Last active March 17, 2020 01:26
Show Gist options
  • Save mcasperson/0c0aa32030417123320627b5a38ad49c to your computer and use it in GitHub Desktop.
Save mcasperson/0c0aa32030417123320627b5a38ad49c to your computer and use it in GitHub Desktop.
Tomcat users example

tomcat-users.xml

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

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>

run

# find the existing cmd command for the image. returns "catalina.sh run"
docker inspect -f '{{.Config.Cmd}}' tomcat:9.0
# map new context.xml and tomcat-users.xml files, move the webapps.dist dir, and start
docker run `
  --name tomcat `
  -it `
  -p 8081:8080 `
  -v C:\temp\tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml `
  -v C:\temp\context.xml:/usr/local/tomcat/webapps.dist/manager/META-INF/context.xml `
  tomcat:9.0 `
  /bin/bash -c "mv /usr/local/tomcat/webapps /usr/local/tomcat/webapps2; mv /usr/local/tomcat/webapps.dist /usr/local/tomcat/webapps; catalina.sh run"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment