This article directory
1. Whether to install Docker
- You can verify that Docker is installed with the following command:
docker --version
As you can see, after entering this command, the Docker version information is displayed, indicating that Docker has been installed.
2. Pull the Tomcat image
- You can pull the Tomcat image from Docker Hub with the following command:
docker pull tomcat
This will download the latest version of the Tomcat image into the virtual machine.
3. Run the Tomcat container
- Run the Tomcat container in Docker with the following command, while mapping port 8082 of the host machine to port 8080 of the container:
docker run -d -p 8082:8080 --name my-tomcat tomcat:latest
This will run a my-tomcat
Tomcat container named in the background and map the host's port 8082 to the container's port 8080.
4. Verify that the Tomcat container is running
- Run the following command to verify that the Tomcat container is running successfully:
docker ps
This will list all running Docker containers. You can see a my-tomcat
container named .
5. Test Tomcat access
- Enter the following address in the browser to test access to the Tomcat container:
http://localhost:8082/
As shown in the image above, the resource cannot be displayed.
You can enter the container to find the problem:
It is found that the welcome interface is not in webapps
the folder ( tomcat
the path where the default welcome page is actually placed should be webapps/ROOT/index.jsp
or index.html
), but webapps.dist
in .
So there is a solution: copy webapps.dist
the contents of the directory to webapps
the directory:
cp -r webapps.dist/* webapps/
Access the interface again as follows:
6. Open port 8082
Open port 8082 in the virtual machine's firewall to ensure that the Tomcat container can be accessed over the network. The port can be opened with the following command:
ufw allow 8082
This will allow incoming HTTP traffic on port 8082.