Cause Analysis:
- Whether it is possible to access the virtual machine (host) address when running a docker container
- Whether the port number corresponding to the virtual machine is turned on or whether the defense wall is turned off
- Is the port mapping correct (this is what I encountered)
- The latest version of tomcat is downloaded. After running docker, there is nothing in it and 404 will be reported.
It is usually caused by these reasons. The docker container is obviously running successfully, but it cannot be accessed normally.
Case recurrence (taking the third reason as an example):
First, I run a tomcat container on docker container
docker run –name tomcat1 -p 8088:8088 -d 108db0e7c85e
Check whether the container is running successfully: docker ps
Enter the address in the browser to access tomcat, but it fails.
This kind of inaccessibility usually means that there is a problem with the port mapping. If 404 is reported, it means that there is a problem with the port, but there is no data in it.
If the above problem occurs, there are two solutions. One is to re-run a container, and the other is to enter the docker container and change the port number of tomcat.
--name container name (can be customized) -p host ip: mapping ip -d image name/image id
1 Re-run a container: docker run –name tomcat2 -p 8089:8080 -d 108db0e7c85e
2 Enter the inaccessible container and modify the tomcat port number
Enter inside the tomcat1 container: docker exec -it tomcat1 bash
The operation here will be more difficult, because text editors such as vi and vim cannot be used in the docker container, and you need to download it yourself.
Solution:
For question 1: To ensure that you can ping the IP of the virtual machine
For question 2, check whether the virtual machine port is developed. If not, open the corresponding port or disable the firewall directly.
Regarding question 3: Pay attention to port mapping. The host port can be defined by yourself, but the port mapped by the container must be the same as the configured port of the application. For example, nginx defaults to 80 and tomcat defaults to 8080. If it is already running and you do not want to delete the container, you can enter inside container
Modify application port number
Regarding question 4: The latest version of tomcat can be used, but there is no content in webapps by default.