Docker部署tomcat出现404错误

docker下载最新的tomcat启动,映射端口并启动:

docker run -p 8888:8080 tomcat

 启动以后,浏览器输入http//:ip:8888 ,我的ip是192.168.1.106,浏览器输入http:192.168.1.106:8888,浏览器会报错404

HTTP Status 404 – Not Found

在docker的tomcat镜像文件地址找到说明,现在默认的tomcat镜像,都不再提供admin界面了,需要自己修改。

https://hub.docker.com/_/tomcat

Note: as of docker-library/tomcat#181, the upstream-provided (example) webapps are not enabled by default, per upstream's security recommendations, but are still available under the webapps.dist folder within the image to make them easier to re-enable.

修改方式如下:

启动tomcat

docker run -p 8888:8080 tomcat

查看docker container id

root@04e013d4416f:/usr/local/tomcat/webapps# [root@localhost local]# docker ps
CONTAINER ID        IMAGE                         COMMAND             CREATED             STATUS              PORTS                    NAMES
fb98132b4582        tomcat   "catalina.sh run"   6 minutes ago       Up 6 minutes        0.0.0.0:8888->8080/tcp   wizardly_proskuriakova 

进入docker container

[root@localhost local]# docker exec -it fb98132b4582 /bash/bin 

可以看到tomcat的根目录下有两个文件夹webapps.dist 和webapps,webapps现在是空,把webapps删掉,把webapps.dist 拷贝一份,改名字为webapps。

[root@localhost local]# docker exec -it fb98132b4582 /bin/bash
root@fb98132b4582:/usr/local/tomcat# pwd
/usr/local/tomcat
root@fb98132b4582:/usr/local/tomcat# ls
BUILDING.txt  CONTRIBUTING.md  LICENSE    NOTICE    README.md  RELEASE-NOTES  RUNNING.txt  bin  conf  include  lib    logs  native-jni-lib  temp  webapps  webapps.dist  work
root@fb98132b4582:/usr/local/tomcat# rm -R webapps
root@fb98132b4582:/usr/local/tomcat# cp -R webapps.dist webapps
root@fb98132b4582:/usr/local/tomcat# 
 

 这时候查看webapps,就会发现熟悉的内容了

root@fb98132b4582:/usr/local/tomcat# cd webapps
root@fb98132b4582:/usr/local/tomcat/webapps# ls
ROOT  docs  examples  host-manager  manager
root@fb98132b4582:/usr/local/tomcat/webapps# 

这时候用浏览器登陆 http://192.168.1.106:8888

就可以看到admin界面了

你可能感兴趣的:(docker)