小白都能懂的 玩转docker系列之 部署tomcat练习

今天开始安装tomcat

#官方使用方式,用完即删,适合测试
[root@xiaoxiao ~]# docker run -it --rm tomcat:9.0
Unable to find image 'tomcat:9.0' locally
9.0: Pulling from library/tomcat
d6ff36c9ec48: Pull complete 
c958d65b3090: Pull complete 
edaf0a6b092f: Pull complete 
80931cf68816: Pull complete 
bf04b6bbed0c: Pull complete 
8bf847804f9e: Pull complete 
fa776a6e7e37: Pull complete 
586534165c2f: Pull complete 
0f6d126a6962: Pull complete 
9f3317edffb3: Pull complete 
Digest: sha256:9de2415ccf10fe8e5906e4b72eda21649a7a1d0b88e9111f8409062599f3728e

#这种方式,docker ps看不到镜像
[root@xiaoxiao ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@xiaoxiao ~]# 

#下载再启动
docker pull tomcat

#测试
[root@xiaoxiao ~]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
Digest: sha256:9de2415ccf10fe8e5906e4b72eda21649a7a1d0b88e9111f8409062599f3728e
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
[root@xiaoxiao ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              4bb46517cac3        2 weeks ago         133MB
centos              latest              0d120b6ccaa8        2 weeks ago         215MB
tomcat              9.0                 2ae23eb477aa        3 weeks ago         647MB
tomcat              latest              2ae23eb477aa        3 weeks ago         647MB
#启动运行
docker run

#测试
[root@xiaoxiao ~]# docker run -d -p 3355:8080 --name tomcat01 tomcat
e383e6f95c8b59cd1c64ac0ea75b1fcc9291d506984add134cd2f36f3b2ad189
#进入容器
docker exec

#调试
[root@xiaoxiao ~]# docker exec -it tomcat01 /bin/bash
root@e383e6f95c8b:/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

在这里插入图片描述

#发现问题,linux命令少了,以及没有webapps
#是由于阿里云镜像是最小镜像,所有没必要的都去除,保证最小可运行环境

#webapps.dist里面是webapp的所有内容
root@e383e6f95c8b:/usr/local/tomcat/webapps.dist# ls
ROOT  docs  examples  host-manager  manager

#,将.dist的内容拷贝到webapps
root@e383e6f95c8b:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@e383e6f95c8b:/usr/local/tomcat/webapps# ls
ROOT  docs  examples  host-manager  manager

这样就ok了
在这里插入图片描述
注意要将安全组放通~在这里插入图片描述
好了,tomcat就部署完了

猜你喜欢

转载自blog.csdn.net/weixin_45806131/article/details/108272788