Docker deploys Tomcat and opens port 8082

1. Whether to install Docker

  • You can verify that Docker is installed with the following command:
docker --version

insert image description here

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

insert image description here

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

insert image description here

This will run a my-tomcatTomcat 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

insert image description here

This will list all running Docker containers. You can see a my-tomcatcontainer named .

5. Test Tomcat access

  • Enter the following address in the browser to test access to the Tomcat container:
http://localhost:8082/

insert image description here

As shown in the image above, the resource cannot be displayed.

You can enter the container to find the problem:

insert image description here

It is found that the welcome interface is not in webappsthe folder ( tomcatthe path where the default welcome page is actually placed should be webapps/ROOT/index.jspor index.html), but webapps.distin .

So there is a solution: copy webapps.distthe contents of the directory to webappsthe directory:

cp -r webapps.dist/* webapps/

insert image description here

Access the interface again as follows:

insert image description here

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

insert image description here

This will allow incoming HTTP traffic on port 8082.

Guess you like

Origin blog.csdn.net/m0_51913750/article/details/131520590