docker启动tomcat容器访问端口显示404

转载自:https://blog.csdn.net/qq_45589050/article/details/104559125

如果已经关闭防火墙,还出现404问题,那么就确定是tomcat的webapps文件夹下没有东西

  • 启动Tomcat容器
docker run -d -p 8888:8080 tomcat
  • 查看已经启动的容器
docker ps

使用8888端口访问Tomcat失败
docker启动tomcat容器访问端口显示404_第1张图片
先查看防火墙状况

service firewalld status

如果防火墙没关闭,先关闭防火墙

# 关闭防火墙
systemctl stop firewalld.service
# 禁止防火墙开机启动
systemctl disable firewalld.service
# 启动docker
systemctl start docker
# 重启docker
systemctl restart docker

如果防火墙已经关闭但访问tomcat还是失败,那么使用如下命名进入tomcat的目录

docker exec -it af1a3dbdb0bd(启动的tomcat容器的容器id) /bin/bash

查看当前文件夹内的所有文件

root@af1a3dbdb0bd:/usr/local/tomcat# ls -al
total 124
drwxr-xr-x 1 root root    30 Aug  5 19:22 .
drwxr-xr-x 1 root root    20 Aug  5 19:18 ..
-rw-r--r-- 1 root root 18982 Jun 30 20:14 BUILDING.txt
-rw-r--r-- 1 root root  5409 Jun 30 20:14 CONTRIBUTING.md
-rw-r--r-- 1 root root 57092 Jun 30 20:14 LICENSE
-rw-r--r-- 1 root root  2333 Jun 30 20:14 NOTICE
-rw-r--r-- 1 root root  3255 Jun 30 20:14 README.md
-rw-r--r-- 1 root root  6898 Jun 30 20:14 RELEASE-NOTES
-rw-r--r-- 1 root root 16262 Jun 30 20:14 RUNNING.txt
drwxr-xr-x 2 root root  4096 Aug  5 19:23 bin
drwxr-xr-x 1 root root    22 Aug  9 08:49 conf
drwxr-xr-x 2 root root  4096 Aug  5 19:22 lib
drwxrwxrwx 1 root root   177 Aug  9 08:49 logs
drwxr-xr-x 2 root root   134 Aug  5 19:22 native-jni-lib
drwxrwxrwx 2 root root    30 Aug  5 19:22 temp
drwxr-xr-x 2 root root     6 Aug  5 19:22 webapps
drwxr-xr-x 7 root root    81 Jun 30 20:12 webapps.dist
drwxrwxrwx 2 root root     6 Jun 30 20:09 work

进入webapps文件夹下,如果显示total 0,我们就需要把webapps.dist中的内容复制到webapps文件夹下

root@af1a3dbdb0bd:/usr/local/tomcat/webapps# ls -al
total 0
drwxr-xr-x 2 root root  6 Aug  5 19:22 .
drwxr-xr-x 1 root root 30 Aug  5 19:22 ..
cd webapps
rm -f webapps
cp -r webapps.dist webapps

然后查看是否有可运行的容器

docker ps

[root@bigdata01 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
af1a3dbdb0bd        tomcat              "catalina.sh run"   5 minutes ago       Up 5 minutes        0.0.0.0:8088->8080/tcp   cranky_meninsky

访问ip:主机端口(8888) 即可访问成功
docker启动tomcat容器访问端口显示404_第2张图片

你可能感兴趣的:(Error,合集,Docker学习指南)