Docker deploys multiple tomcat containers and cannot access the default page

When learning docker recently, I deployed multiple tomcat containers and found that the welcome page of tomcat could not be accessed normally.
Of course, I found that the application could not be accessed. The first thing to do is to check in order

   netstat -anp | more   # 查看端口监听是否开启

//再去手动开一下访问的端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload

But my problem is that using a simple command to start the tomcat container can be accessed normally.
When the data volume is configured, the page cannot be accessed.

docker run -d -p 8080:8080 --name  tomcat8080  镜像id

 docker run -d -p 8080:8080 --name my_tomcat -v    \
 /opt/vol_tomcat/webapps:/usr/local/tomcat/webapps  镜像id

The root of the problem : the tomcat welcome page itself is an application, which is realized by multiple files in the webapps directory of tomcat installed by default.

But in the host directory /op/vol_tomcat/webapps is an empty directory, which leads to multiple containers tomcat started with this data volume

The /usr/local/tomcat/webapps directory is also empty, so no pages can be displayed.

insert image description here
The solution
is to get a set of these tomcat default files. You can use a non-data volume method to start a tomcat container, then cp a copy to the host, and then use
this data to roll up n tomcat containers, and ensure that the contents of these containers are exactly the same

# 非数据卷方式起一个tomcat容器
docker run -d -p 8080:8080 --name  tomcat8080  镜像id
# docker cp 将容器内的webapps 目录拷出到宿主机目录
docker cp tomcat8080:/usr/local/tomcat/webapps /opt/vol_tomcat
# 然后可以用这个数据卷去起很多的tomcat都是可以看到主页的

 docker run -d -p 8081:8080 --name tomcat8081 -v /opt/vol_tomcat/webapps:/usr/local/tomcat/webapps  镜像id
 docker run -d -p 8082:8080 --name tomcat8082 -v /opt/vol_tomcat/webapps:/usr/local/tomcat/webapps  镜像id
 docker run -d -p 8083:8080 --name tomcat8083 -v /opt/vol_tomcat/webapps:/usr/local/tomcat/webapps  镜像id

But inexplicably feel that this is no different from java -jar starting the specified port...

Guess you like

Origin blog.csdn.net/weixin_48011779/article/details/125512277