docker部署Tomcat 服务器
大家好,今天来分享使用docker部署Tomcat服务器
首先呢,大家可以去dicker 官网上去看
第一步: 拉取镜像 你可以不指定版本标签(默认下下载最新的,我这个时候,最新的是10)
[root@localhost ~]# docker pull tomcat:9.0 9.0: Pulling from library/tomcat 0e29546d541c: Pull complete 9b829c73b52b: Pull complete cb5b7ae36172: Pull complete 6494e4811622: Pull complete 668f6fcc5fa5: Pull complete dc120c3e0290: Pull complete 8f7c0eebb7b1: Pull complete 77b694f83996: Pull complete 7662046c36cb: Pull complete b93639122cb4: Pull complete Digest: sha256:cd96d4f7d3f5fc4d3bc1622ec678207087b8215d55021a607ecaefba80b403ea Status: Downloaded newer image for tomcat:9.0 docker.io/library/tomcat:9.0
查看镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 605c77e624dd 2 months ago 141MB tomcat 9.0 b8e65a4d736d 2 months ago 680MB mysql latest 3218b38490ce 2 months ago 516MB hello-world latest feb5d9fea6a5 5 months ago 13.3kB centos latest 5d0da3dc9764 5 months ago 231MB
我这里做一个端口映射,我这里走的是最新的,因为
-name tomcat01 tomcat 没有加上指定的版本
[root@localhost ~]# docker run -d -p 3355:8080 --name tomcat01 tomcat Unable to find image tomcat:latest locally latest: Pulling from library/tomcat 0e29546d541c: Already exists 9b829c73b52b: Already exists cb5b7ae36172: Already exists 6494e4811622: Already exists 668f6fcc5fa5: Already exists dc120c3e0290: Already exists 8f7c0eebb7b1: Already exists 77b694f83996: Already exists 0f611256ec3a: Pull complete 4f25def12f23: Pull complete Digest: sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324 Status: Downloaded newer image for tomcat:latest
不过也是可以做的
我们就拿最新的来做
可以在本地进行测试
[root@localhost ~]# curl localhost:3355 <!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body { font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b { color:white;background-color:#525D76;} h1 { font-size:22px;} h2 { font-size:16px;} h3 { font-size:14px;} p { font-size:12px;} a { color:black;} .line { height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache To
经过本地测试,我们发现,初始化的前端网站页面不完整
但是不影响我们对页面的访问(可以连接成功)
使用浏览器测试Tomcat
http://192.168.1.12:3355
发现有404 因为Tomcat进行本身就是不完整的
但是不影响我们正常的访问
这是Tomcat 容器的内外网端口映射关系
进入Tomcat容器
[root@localhost ~]# docker exec -it tomcat01 /bin/bash root@155ead9f80cc:/usr/local/tomcat#
这是Tomcat内部的文件结构: 发现这里没有东西 ,这是不行的
root@155ead9f80cc:/usr/local/tomcat# ls webapps root@155ead9f80cc:/usr/local/tomcat#
这样复制一下文件到指定文件中
root@155ead9f80cc:/usr/local/tomcat# cp -r webapps.dist/* webapps root@155ead9f80cc:/usr/local/tomcat# cd webapps root@155ead9f80cc:/usr/local/tomcat/webapps# ls ROOT docs examples host-manager manager
给大家看清楚一点
然后: 咱们刷新一下网页 这就可以了 因为镜像本身并不完整,只有维持正常功能的模块,所以我们讲一个现成的页面文件复制到前端页面的文件夹当中
这就完成了我们这个docker部署Tomcat 服务器 好了,谢谢大家