跳到主要内容

二十五、Docker 安装 Tomcat

Tomcat 是 Java Web 最流行的容器之一,Docker 安装 Tomcat 有两种方法

我们以当前最新的版本 9.0.8 安装为例

因为Tomcat 需要 Java 环境,我们使用的是 jre8

1. docker pull tomcat

这种方法非常适合只需要使用 Tomcat 的开发者

1、 查找DockerHub上的tomcat镜像;

    [root@pottercoding.cn ~]# docker search tomcat
NAME DESCRIPTION OFFICIAL
tomcat Apache Tomcat is an open source ... [OK]
...
有很多版本,我们选择官方的 tomcat

2、 拉取官方的镜像,标签为9.0.8-jre8

    [root@pottercoding.cn ~]# docker pull tomcat:9.0.8-jre8
9.0.8-jre8: Pulling from library/tomcat

3、 稍等片刻,就能在本地镜像列表里看到tomcat了;

    [root@pottercoding.cn ~]# docker images tomcat
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 9.0.8-jre8 fffeb191ae8c 2 weeks ago 465.6 MB
一个 Tomcat 容器 400m ....

4、 通过Dockerfile构建;

可以使用 Dockerfile 定制自己的 Tomcat 容器

1、 创建目录tomcat,用于存放后面的相关东西;

    [root@pottercoding.cn ~]# mkdir -p ~/tomcat/webapps ~/tomcat/logs ~/tomcat/conf