通过docker方式安装tomcat服务
工具/原料
Linux终端
方法/步骤
1、查找DockerHub上的tomcat镜像[root@localhost/]#dockersearchtomcat
2、拉取官方的镜像[root@localhost/]#dockerpulltomcat
3、查看镜像[root@localhost/]#dockerimagestomcat
4、使用Tomcat默认的配置来启动一个Tomcat容器[root@localhost/]#do罕铞泱殳cker惺绅寨瞀run-d-p8080:8080--nametomcattomcat:latest
5、创建Tomcat目录[root@localhost/]#mkdir-p/usr/app/tomcat
6、拷贝容器内Tomcat配置文件和日志到本地[root@localhost/]#咯悝滩镞dockercptomcat:/usr/local/tomcat/conf砖镑苣逢/usr/app/tomcat/conf[root@localhost/]#dockercptomcat:/usr/local/tomcat/logs/usr/app/tomcat/logs
7、停止tomcat容器[root@localhost/]#dockerstoptomcat
8、删除tomcat容器[root@localhost/]#dockerrmtomcat
9、创建并运行tomcat容器[root@localhost/]#dockerrun颍骈城茇-d-p8080:8080--nametomcat-v/usr/app/tomcat/w髫潋啜缅ebapps:/usr/local/tomcat/webapps-v/usr/app/tomcat/conf:/usr/local/tomcat/conf-v/usr/app/tomcat/logs:/usr/local/tomcat/logs--restart=alwaystomcat:latest
10、查看创建的容器[root@localhost/]#dockerps|greptomcat
11、查看容器的i圬桦孰礅p地址[root@localhost/]#dockerinspect--format='{{.Netw泠贾高框orkSettings.IPAddress}}'tomcat
12、查看firewalld状态[root@localhost/]#systemctlstatusfirewalld
13、开启firewalld(可选,未开启时执行)[root@localhost/]#systemctlstartfirewalld
14、开放8080端口[root@localhost/]#firewall-cmd--zone=public--add-port=8080/tcp--permanent
15、重新载入[root@localhost/]#firewall-cmd--reload
16、查看是否生效[root@localhost/]#firewall-cmd--zone=public--query-port=8080/tcp
17、查看Tomcat日志[root@localhost/]#dockerlogs-f-t--tail20tomcat