
This assumes you have installed Tomcat on Docker, and that the Tomcat container is up and running. Let's say the name of the container is "tomcat".
~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
24d6d3fa99a3 tomcat "catalina.sh run" 5 seconds ago Up 5 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp tomcat
By default, after a clean install of Tomcat on Docker, the /usr/local/tomcat/webapps directory in the container will be empty, which you can see with the docker exec command.
~]# docker exec tomcat ls -l /usr/local/tomcat
total 0
Let's say you have a WAR file named helloworld.war that you want to deploy to Tomcat, and that the helloworld.war file is located at /tmp/helloworld.war on the Docker system. The docker cp command can be used to copy the WAR file to /usr/local/tomcat/webapps in the Tomcat container.
docker cp /tmp/helloworld.war tomcat:/usr/local/tomcat/webapps
If autoDeploy in the <tomcat_home>/conf/server.xml file is set to true, <tomcat_home>/conf/server.xml file, give Tomcat a few moments to expand the WAR. Check out my article on deploying a WAR to Tomcat for more details on this.
<Host appBase="webapps"
autoDeploy="true"
deployOnStartup="true"
deployXML="true"
name="localhost"
unpackWARs="true">
If autoDeploy is false and deployOnStartup is true, use the docker restart command to restart the container.
docker restart tomcat
Or, use the docker exec command to stop and then start Tomcat.
docker exec tomcat catalina.sh stop
docker exec tomcat catalina.sh start
Give Tomcat a few moments to expand the WAR, and then you should see the following in the Tomcat container.
~]# docker exec tomcat ls -l /usr/local/tomcat/webapps
total 4
drwxr-x--- 4 root root 54 Oct 21 04:46 helloworld
-rwxr-xr-x 1 root root 1025 Oct 21 04:37 helloworld.war
You should then be able to access the application, something like this.
Did you find this article helpful?
If so, consider buying me a coffee over at