通过Docker部署tomcat
1.通过:docker pull tomcat,拉取tomcat最新的镜像文件,或者通过:docker pull tomcat:x.x,拉取指定版本的tomcat镜像文件
cdc@cdcs-MacBook-Pro / % docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
6c33745f49b4: Pull complete
ef072fc32a84: Pull complete
c0afb8e68e0b: Pull complete
d599c07d28e6: Pull complete
e8a829023b97: Pull complete
d04be46a31d1: Pull complete
db6007c69c35: Pull complete
e4ad4c894bce: Pull complete
248895fda357: Pull complete
277059b4cba2: Pull complete
Digest: sha256:57dae7dfb9b62a413cde65334c8a18893795cac70afc3be589c8336d8244655d
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
2.通过:docker run,运行容器
cdc@cdcs-MacBook-Pro / % docker run -d -p 3355:8080 --name test_tomcat tomcat
9fce498cd6400831757fb08c019cb61dabce767c00e24f86ed08df026a99ea7c
3.直接访问暴露在外部的端口3355,访问tomcat
发现404,表明访问失败,但是tomcat是运行成功的,只是未找到文件
4.进入到tomcat容器中的webapps目录下,发现里面没有文件,而tomcat在运行时,会去加载webapps目录下的文件信息,所以在访问tomcat时,出现404的错误。
root@9fce498cd640:/usr/local/tomcat# ls
BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp webapps.dist
CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps work
root@9fce498cd640:/usr/local/tomcat# cd webapps
root@9fce498cd640:/usr/local/tomcat/webapps# ls
root@9fce498cd640:/usr/local/tomcat/webapps#
5.但是发现在webapps.dist有对应的文件信息,因此将webapps.dist中的文件信息,复制到webapps目录下
root@9fce498cd640:/usr/local/tomcat# cd webapps.dist/
root@9fce498cd640:/usr/local/tomcat/webapps.dist# ls
ROOT docs examples host-manager manager
root@9fce498cd640:/usr/local/tomcat/webapps.dist# cd ..
root@9fce498cd640:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@9fce498cd640:/usr/local/tomcat# cd webapps
root@9fce498cd640:/usr/local/tomcat/webapps# ls
ROOT docs examples host-manager manager
6.再次访问tomcat,显示成功。