tomcat部署web項目非常方便,把war包放到webapps目錄就可以了。本篇使用docker快速搭建一個tomcat環(huán)境
拉取官方最新版tomcat鏡像
[root@yoyo ~]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
6f2f362378c5: Pull complete
494c27a8a6b8: Pull complete
7596bb83081b: Pull complete
372744b62d49: Pull complete
fb72767f9beb: Pull complete
3fe571af508a: Pull complete
3e6725074325: Pull complete
9ffd5dadda90: Pull complete
4e051c2969b0: Pull complete
b326a8316680: Pull complete
Digest: sha256:cea26a23e1ebdbebdddde1e02a10e655b0b386d8de6002301a037a08be87a12f
Status: Downloaded newer image for tomcat:latest
查看已下載的鏡像文件
[root@yoyo ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos v7.5 254d4dfe9df7 3 days ago 200MB
tomcat latest 5377fd8533c3 2 weeks ago 506MB
mysql 5.6 3ed1080b793f 2 weeks ago 256MB
mysql 5.7 a1aa4f76fab9 2 weeks ago 373MB
centos/python-36-centos7 latest b8d15efaa8ec 2 months ago 651MB
centos centos7.5.1804 cf49811e3cdb 3 months ago 200MB
ubuntu 15.10 9b9cb95443b5 2 years ago 137MB
training/webapp latest 6fae60ef3446 4 years ago 349MB
使用docker run 運行一個tomcat的容器
—name yoyotomcat 容器重命名yoyotomcat
-p 8090:8080 容器的8080端口映射到主機的8090端口
-v ~/yoyo/tomcat/webapps/jenkins:/usr/local/tomcat/webapps/jenkins 容器的/usr/local/tomcat/webapps/jenkins 目錄掛載到本機~/yoyo/tomcat/webapps/jenkins
-d 掛后臺運行
docker run —name yoyotomcat -p 8090:8080 -v ~/yoyo/tomcat/webapps/jenkins:/usr/local/tomcat/webapps/jenkins -d tomcat
運行成功后 docker ps查看已運行容器
[root@yoyo jenkins]# docker run --name yoyotomcat -p 8090:8080 -v ~/yoyo/tomcat/webapps/jenkins:/usr/local/tomcat/webapps/jenkins -d tomcat
[root@yoyo jenkins]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1d07763a6eaa tomcat "catalina.sh run" 15 minutes ago Up 7 minutes 0.0.0.0:8090->8080/tcp yoyotomcat
643c1f7c970c mysql:5.7 "docker-entrypoint.s…" 8 hours ago Up 27 minutes 33060/tcp, 0.0.0.0:3309->3306/tcp yoyomysql
37a3b50d151c mysql:5.6 "docker-entrypoint.s…" 25 hours ago Up 26 minutes 0.0.0.0:3308->3306/tcp mymysql
[root@yoyo jenkins]#
如果用的是阿里云服務器,需在后臺開放8090端口,這樣在瀏覽器輸入http://主機ip:8090就能訪問到tomcat首頁了
tomcat環(huán)境已經(jīng)部署完成,接下來把war包放到tomcat下的webapps目錄就可以了,也就是/usr/local/tomcat/webapps。
前面啟動的時候,/usr/local/tomcat/webapps/jenkins目錄是掛載到本機的~/yoyo/tomcat/webapps/jenkins目錄。
只需下載jenkins.war放到jenkins目錄就可以了
cd 到~/yoyo/tomcat/webapps/jenkins/目錄
wget 下載jenkins.war
jar -xvf 解壓jenkins.war
[root@yoyo jenkins]# cd ~/yoyo/tomcat/webapps/jenkins/
[root@yoyo jenkins]# wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war
--2019-06-30 19:40:15-- http://mirrors.jenkins-ci.org/war/latest/jenkins.war
Resolving mirrors.jenkins-ci.org (mirrors.jenkins-ci.org)... 52.202.51.185
Connecting to mirrors.jenkins-ci.org (mirrors.jenkins-ci.org)|52.202.51.185|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://mirrors.tuna.tsinghua.edu.cn/jenkins/war/2.182/jenkins.war [following]
--2019-06-30 19:40:16-- http://mirrors.tuna.tsinghua.edu.cn/jenkins/war/2.182/jenkins.war
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 77565765 (74M) [application/java-archive]
Saving to: 'jenkins.war’
100%[=====================================================================================================================>] 77,565,765 12.1MB/s in 5.1s
2019-06-30 19:40:22 (14.4 MB/s) - 'jenkins.war’ saved [77565765/77565765]
[root@yoyo jenkins]# jar -xvf jenkins.war
解壓之后的目錄
[root@yoyo jenkins]# ll
total 78212
drwxr-xr-x 3 root root 4096 Jun 23 20:22 bootstrap
-rw-r--r-- 1 root root 1946 Feb 7 12:49 ColorFormatter.class
drwxr-xr-x 5 root root 4096 Jun 23 20:22 css
-rw-r--r-- 1 root root 1544 Jun 23 20:18 dc-license.txt
drwxr-xr-x 2 root root 4096 Jun 23 20:22 executable
-rw-r--r-- 1 root root 17542 Jun 23 20:18 favicon.ico
drwxr-xr-x 12 root root 4096 Jun 23 20:22 help
drwxr-xr-x 6 root root 4096 Jun 23 20:22 images
-rw-r--r-- 1 root root 77565765 Jun 24 11:22 jenkins.war
-rw-r--r-- 1 root root 1674 Feb 7 12:49 JNLPMain.class
drwxr-xr-x 2 root root 4096 Jun 23 20:22 jsbundles
-rw-r--r-- 1 root root 862 Feb 7 12:49 LogFileOutputStream$1.class
-rw-r--r-- 1 root root 636 Feb 7 12:49 LogFileOutputStream$2.class
-rw-r--r-- 1 root root 2240 Feb 7 12:49 LogFileOutputStream.class
-rw-r--r-- 1 root root 20730 Feb 7 12:49 Main.class
-rw-r--r-- 1 root root 1048 Feb 7 12:49 MainDialog$1$1.class
-rw-r--r-- 1 root root 1067 Feb 7 12:49 MainDialog$1.class
-rw-r--r-- 1 root root 2633 Feb 7 12:49 MainDialog.class
-rw-r--r-- 1 root root 512 Feb 7 12:49 Main$FileAndDescription.class
drwxr-xr-x 3 root root 4096 Jun 30 19:22 META-INF
-rw-r--r-- 1 root root 71 Jun 23 20:18 robots.txt
drwxr-xr-x 3 root root 4096 Jun 23 20:22 scripts
drwxr-xr-x 7 root root 4096 Jun 23 20:22 WEB-INF
-rw-r--r-- 1 root root 2390099 May 12 15:50 winstone.jar
[root@yoyo jenkins]#
接著重啟tomcat容器就可以生效了
docker restart yoyotomcat
瀏覽器輸入訪問地址:http://主機ip:8090/jenkins就能訪問到主頁面了
上面是通過掛載tomcat下的webapps目錄,在本機上把war包放進去的方式。如果不掛載容器的目錄,試了下也是可以把war包放進去的
一個tomca鏡像可以啟動多個容器實例,可以再啟動一個yytomcat的容器實例,映射到主機的8091端口
[root@yoyo jenkins]# docker run --name yytomcat -p 8091:8080 -d tomcat
08af0192b961f1ba1bb1bf1edada968822f3143e5f57c59c396fd3fd948e7529
[root@yoyo jenkins]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
08af0192b961 tomcat "catalina.sh run" 3 hours ago Up 3 hours 0.0.0.0:8091->8080/tcp yytomcat
1d07763a6eaa tomcat "catalina.sh run" 4 hours ago Up 3 hours 0.0.0.0:8090->8080/tcp yoyotomcat
643c1f7c970c mysql:5.7 "docker-entrypoint.s…" 11 hours ago Up 4 hours 33060/tcp, 0.0.0.0:3309->3306/tcp yoyomysql
37a3b50d151c mysql:5.6 "docker-entrypoint.s…" 28 hours ago Up 4 hours 0.0.0.0:3308->3306/tcp mymysql
[root@yoyo jenkins]#
啟動完成后在瀏覽器輸入http://主機ip:8091就可以訪問到tomcat首頁了,接著用docker cp 把本機的war包復制到y(tǒng)ytomcat容器里面
接著前面下載jenkins.war并解壓到~/yoyo/tomcat/webapps/jenkins/目錄步驟
docker cp 復制 jenkins整個目錄到 容器的/usr/local/tomcat/webapps/jenkins目錄
docker exec -it yytomcat /bin/bash 進入運行容器的交互環(huán)境
cd 到tomcat容器的webapps/jenkins目錄,查看到已經(jīng)復制成功
exit 退出容器
docker restart 重啟容器
[root@yoyo ~]# docker cp ~/yoyo/tomcat/webapps/jenkins/ yytomcat:/usr/local/tomcat/webapps/jenkins
[root@yoyo ~]# docker exec -it yytomcat /bin/bash
root@08af0192b961:/usr/local/tomcat# cd webapps/jenkins
root@08af0192b961:/usr/local/tomcat/webapps/jenkins# ls
ColorFormatter.class LogFileOutputStream.class MainDialog$1$1.class bootstrap favicon.ico jsbundles
JNLPMain.class META-INF MainDialog$1.class css help robots.txt
LogFileOutputStream$1.class Main$FileAndDescription.class MainDialog.class dc-license.txt images scripts
LogFileOutputStream$2.class Main.class WEB-INF executable jenkins.war winstone.jar
root@08af0192b961:/usr/local/tomcat/webapps/jenkins#
root@08af0192b961:/usr/local/tomcat/webapps/jenkins# exit
exit
[root@yoyo ~]# docker restart yytomcat
yytomcat
[root@yoyo ~]#
瀏覽器輸入訪問地址:http://主機ip:8091/jenkins就能訪問到主頁面了
第9期《python3接口自動化測試》課程,6月29號開學!
主講老師:上海-悠悠
上課方式:QQ群視頻在線教學
本期上課時間:6月29號-7月28號,每周六、周日晚上20:30-22:30
課表詳情:https://www.cnblogs.com/yoyoketang/p/11030218.html
課表詳情,點左下角