Docker部署Tomcat

# 官方使用
# 之前我们都是后台启动,停止容器后,仍可以通过docker ps -a命令查到容器的使用记录
# --rm表示用完就删除容器及历史记录,通过命令查不到;
docker run -it --rm tomcat:9.0
 

# 1、下载 tomcat

[root@iZ2vcfsvipso9tjpqp6fuyZ home]# docker pull tomcat
Using default tag: latest
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
docker.io/library/tomcat:latest
 

# 2、查看是否下载成功

[root@iZ2vcfsvipso9tjpqp6fuyZ home]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
nginx         latest    605c77e624dd   17 months ago   141MB
tomcat        9.0       b8e65a4d736d   18 months ago   680MB
tomcat        latest    fb5657adc892   18 months ago   680MB

# 3、tomcat启动运行

[root@iZ2vcfsvipso9tjpqp6fuyZ home]# docker run -d -p  3355:8080 --name tomcat01 tomcat
a241b290c0ff3b18c5ecb093d590ed7c43b3b9660a0a1761f76f5cf4c242a70d
但是通过外网不能访问

原因:# 进入容器,发现webapps为空,阿里云镜像原因,默认是下载最小的镜像,不必要的都剔除
[root@iZ2vcfsvipso9tjpqp6fuyZ home]# docker exec -it tomcat01 /bin/bash
root@a241b290c0ff:/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@a241b290c0ff:/usr/local/tomcat# cd webapps
root@a241b290c0ff:/usr/local/tomcat/webapps# ls
root@a241b290c0ff:/usr/local/tomcat/webapps# cd /
root@a241b290c0ff:/# cd /usr/local/tomcat/

# 将webapps.dist 中的所有文件复制到wabapps中
root@a241b290c0ff:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@a241b290c0ff:/usr/local/tomcat# cd webapps
root@a241b290c0ff:/usr/local/tomcat/webapps# ls
ROOT  docs  examples  host-manager  manager
外网可以正常访问tomcat

参考狂神说Docker15、作业二:部署Tomcat_哔哩哔哩_bilibili

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值