下载tomcat镜像
[root@bogon data]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
9cc2ad81d40d: Pulling fs layer
e6cb98e32a52: Pulling fs layer
ae1b8d879bad: Downloading
42cfa3699b05: Waiting
8d27062ef0ea: Waiting
9b91647396e3: Waiting
7498c1055ea3: Waiting
a183d8c2c929: Waiting
73dd800dda4c: Waiting
2bc71ef979ec: Waiting
latest: Pulling from library/tomcat
9cc2ad81d40d: Pull complete
e6cb98e32a52: Pull complete
ae1b8d879bad: Pull complete
42cfa3699b05: Pull complete
8d27062ef0ea: Pull complete
9b91647396e3: Pull complete
7498c1055ea3: Pull complete
a183d8c2c929: Pull complete
73dd800dda4c: Pull complete
2bc71ef979ec: Pull complete
Digest: sha256:80db17f3efd9cdcd9af7c799097fe0d223bbee8f25aa36234ab56292e3d8bd7b
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
[root@bogon data]#
运行容器
使用docker run 运行一个tomcat的容器
- --name leslietomcat 容器重命名leslietomcat
- -p 8090:8080 容器的8080端口映射到主机的8090端口
- -v ~/leslie/tomcat/webapps/jenkins:/usr/local/tomcat/webapps/jenkins 容器的/usr/local/tomcat/webapps/jenkins 目录挂载到本机~/leslie/tomcat/webapps/jenkins
- -d 挂后台运行
[root@bogon webapps]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8f99aa298cc8 tomcat "catalina.sh run" 59 seconds ago Up 57 seconds 0.0.0.0:8089->8080/tcp leslietomcat
4252c716b85d mysql:5.7 "docker-entrypoint.s…" 2 hours ago Up 2 hours 33060/tcp, 0.0.0.0:3309->3306/tcp lesliemysql
[root@bogon webapps]#
这样在浏览器输入http://主机ip:8089就能访问到tomcat首页了
部署war包
因为自身有Jenkins,所以启动的时候映射到安装目录
[root@bogon /]# docker run --name leslietomcat -p 8089:8080 -v /opt/shaobo/apache-tomcat-9.0.20/webapps:/usr/local/tomcat/webapps -d tomcat