Docker安装tomcat(本地版)

来自CloudWiki
跳转至: 导航搜索

所需软件

一个提前打包好的docker镜像:tomcat.tar

通过CRT将tomcat包上传到centos系统中

加载已上传的tomcat包

[root@controller ~]# docker load -i tomcat.tar

f94641f1fe1f: Loading layer [=========================>]  105.5MB/105.5MB
ec62f19bb3aa: Loading layer [=========================>]  24.08MB/24.08MB
2c719774c1e1: Loading layer [=========================>]  8.005MB/8.005MB
1b958b53b256: Loading layer [=========================>]  2.172MB/2.172MB
7d63f8777ebf: Loading layer [=========================>]  3.584kB/3.584kB
fe60061c6c4e: Loading layer [=========================>]  1.536kB/1.536kB
d38f3d5a39fb: Loading layer [=========================>]    317MB/317MB
2b6c38ff3137: Loading layer [=========================>]   2.56kB/2.56kB
f0e1731fd286: Loading layer [=========================>]  1.894MB/1.894MB
c8bcc49b9925: Loading layer [=========================>]  18.82MB/18.82MB
f24d8b358bb1: Loading layer [=========================>]   2.56kB/2.56kB
f24d8b358bb1: Loading layer [=========================>]   2.56kB/2.56kB
Loaded image: tomcat:latest

查询镜像

[root@controller ~]# docker images

REPOSITORY        TAG               IMAGE ID          CREATED           SIZE
tomcat            latest            3639174793ba      12 days ago       463MB


使用tomcat镜像

运行容器

runoob@runoob:~/tomcat$ docker run --name tomcat -p 8080:8080 -v $PWD/test:/usr/tomcat/webapps/test -d tomcat


命令说明:

-p 8080:8080:将容器的8080端口映射到主机的8080端口

-v $PWD/test:/usr/local/tomcat/webapps/test:将主机中当前目录下的test挂载到容器的/test

查看容器启动情况

runoob@runoob:~/tomcat$ docker ps

CONTAINER ID     IMAGE       COMMAND             CREATED              STATUS            PORTS                    NAMES
37042cce5022     tomcat      "catalina.sh run"   About a minute ago   Up 27 seconds     0.0.0.0:8080->8080/tcp   tomcat

通过浏览器访问: http://10.0.0.20:8080/

(10.0.0.20为宿主机IP)

参考文档:http://www.runoob.com/docker/docker-install-tomcat.html