Docker Install Tomcat

In the past study,I know two ways to install Tomcat with Docker

  1. docker pull tomcat

    • that can find the Tomcat image on Docker Hub
  2. Build with Dockerfile

    • I'm not very good at it but this is important.I'll probably write a separate blog about this approach

I will record the docker install tomcat with dockerhub in this time.

1.search the image in docker hub

https://hub.docker.com/_/tomcat
i can see the commant docker pull tomcat
Copy and paste to pull this image

  • docker search tomcat that can search the version that can install in our device.

docker pull tomcat

i use this to pull the image from dockerhub
when finished docker pull tomcat can see the images that have been downloaded

  • In China the average home already has 100 megabits of Internet speed,but the speed of visiting foreign websites is always extremely slow.
  • thanks for the Chinese Unicorn company like alibaba that can let every one to use their mirrors to speed up.

Use tomcat images

run this comman

docker run --name tomcat -p 8080:8080 -v /test:/usr/local/tomcat/webapps/test -d tomcat  

because of i use WIN10 this time i want to share the folder test in tomcat so i do this , but if we use linux we can user this

docker run --name tomcat -p 8080:8080 -v $PWD/test:/usr/local/tomcat/webapps/test -d tomcat  
  1. -p 8080:8080 Map port 8080 of the container to port 8080 of the host.
  2. -v $PWD/test:/usr/local/tomcat/webapps/test Mount the test in the current directory on the host to the container's /test

docker ps

Check for success,if success ,we will see the tomcat container running.

visit the localhost:8080 check the tomcat running condition

if can you see someting about tomcat on website that you run successfuly.

Some of the problems I had

when i visit the 8080 ,A 404 error occurred.But I realized that tomcat was running successfully.
when i use docker exec -it 68c241f24239 /bin/bash
Enter the tomcat container
use ls -l
see that has two folders webapps and webapps.dist
cd webapps open this folder use ls -l see that it'a empty folder
cd ../webapps.dist change to this folder taht ls -l
see the Root and other files in this folder
The tomcat default welcome page is actually placed in the path.
For demonstration purposes i use mv Root ../webapps
Move the files from the default welcome screen to webapps
then vist the localhost:8080 can see the welcome page

The good news is that I learned the simple principles of tomcat when I was studying the Java web.
Otherwise it will take more time to deal with the problem.