Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Working with MySQL tomcat within Docker is extremely straightforward. 

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

Code Block
languagebash
titleRun the command
docker run -p 3306:33068081:8080 -dit --name mysqltomcat-populated -e MYSQL_ROOT_PASSWORD=<password> -d -server-runtime_1 [-v <path to folder to share with container>:/usr/local/tomcat/webapps/<shared folder>] [-v <path to folder/warfile.war>:/root/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/mysqlhtml

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


Info
titleImportant

//c/ 

//c/ the drive letter must be lower case


Info
titleImportant

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

Code Block
languagebash
titleRun the command
docker run -p 3306:33068081:8080 -dit --name mysql-populatedtomcat-server-runtime_1 -e MYSQL_ROOT_PASSWORD=ppp -dv //c/Users/Selvyn/demo/vm_share/html1:/usr/local/tomcat/webapps/html -v //c/Users/Selvyn/demo/vm_share/mysql:/root mysql-db-unpopulated:latesttomcat-webapps/AppWebTier.war:/usr/local/tomcat/webapps/AppWebTier.war tomcat-server