Tomcat (Docker)

Working with tomcat within Docker is extremely straightforward. 

Begin by downloading tomcat from hub.docker using the pull command docker pull tomcat

Run the command
docker run -p 8081:8080 -dit --name tomcat-server-runtime_1 [-v <path to folder to share with container>:/usr/local/tomcat/webapps/<shared folder>] [-v <path to folder/warfile.war>:/usr/local/tomcat/webapps/<warfile.war>] <image id>

In the command above replace the parameters shown with the values indicated

parametervalue
<password>memorable password, I keep it simple when developing
<path to folder to share with container>

//c/Users/Selvyn/demo/vm_share/html

//c/Users/Selvyn/ must be the path to your account's home directory if you are using windows, or your home directory on Linux/Unix

The demo/vm_share/html can be any directory under your home folder

<path to folder/warfile.war>

//c/Users/Selvyn/demo/vm_share/tomcat-webapps/someapp.war

//c/Users/Selvyn/ must be the path to your account's home directory if you are using windows, or your home directory on Linux/Unix

The demo/vm_share/tomcat-webapps/someapp.war should be the war file you want to deploy - once tomcat has initialised, the war file will automatically be deployed within the webapps folder within the container.

<image id>Should be the image id for mysql if you run docker images

Important

//c/ 

//c/ the drive letter must be lower case

Important

Sharing a war file on the host with a tomcat container via a docker mount

If you update the war file in the host, and you have shared the war file as container mount, it will automatically be redeployed on update.  There is no need to use docker cp to copy the new war file into the container.

Using the above table I use the following command

Run the command
docker run -p 8081:8080 -dit --name tomcat-server-runtime_1 -v //c/Users/Selvyn/demo/vm_share/html1:/usr/local/tomcat/webapps/html -v //c/Users/Selvyn/demo/vm_share/tomcat-webapps/AppWebTier.war:/usr/local/tomcat/webapps/AppWebTier.war tomcat-server