When Testing Java Deployments With Tomcat
When Testing Java Deployments With Tomcat
provides a convenient way to get a server up and running. However, there are a few
tricks to getting the manager application loaded and accessible.
In this blog post, we look at how to boot a Tomcat Docker image ready to accept new
deployments.
Define a user
First, we need to define a Tomcat user that has access to the manager application.
This user is defined in a file called tomcat-users.xml and will be assigned both
the manager-gui and manager-script roles, which grant access to the manager HTML
interface as well as the API:
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="s3cret" roles="manager-gui,manager-script"/>
</tomcat-users>
This blog post provides some more detail about Docker networking with forwarded
ports.
Run the container
The final hurdle to jump is the fact that the Tomcat Docker image does not load any
applications by default. The default applications, such as the manager application,
are saved in a directory called /usr/local/tomcat/webapps.dist. We need to move
this directory to /usr/local/tomcat/webapps. This is achieved by overriding the
command used when launching the container.
The command below maps the two custom XML files we created above (saved
to /tmp in this example),
moves /usr/local/tomcat/webapps.dist to /usr/local/tomcat/webapps, and finally
launches Tomcat:
Conclusion
The Tomcat image maintainers have chosen not to enable the default applications as
a security precaution, but with two custom configuration files and overriding the
Docker command it is possible to boot Tomcat with a fully functional manager
application.
In this post we provided example configuration files and the Docker command to
restore the default applications before running Tomcat.