目录
前言:
本文记录如何用dockerfile创建tomcat8.5.40镜像,因为公司的开发项目需要用到nginx在前端调用多个后端的tomcat服务,因此创建tomcat镜像,实现秒级起多个tomcat服务!
第一步:创建jdk1.8镜像
-
1.1、下载jdk1.8
先到oracle官网下载jdk1.8,需要有oracle官网的帐号和密码(具体请找度娘)
-
1.2、文件存放位置
[root@dingzhi ~]# ls jdk1.8/
dockerfile jdk-8u211-linux-x64.tar.gz
-
1.3、vim dockerfile
FROM centos:latest
MAINTAINER https://blog.csdn.net/lituxiu
ENV TIME_ZOME Asia/Shanghai
ADD jdk-8u211-linux-x64.tar.gz /usr/jdk/
#这里是存放jdk的绝对路径
ENV JAVA_HOME /usr/jdk/jdk1.8.0_211
ENV CLASSPATH $JAVA_HOME/lib;$JAVA_HOME/jre/lib
ENV PATH $PATH:$JAVA_HOME/bin
-
1.4、创建jdk-1.8镜像
[root@dingzhi ~]# cd jdk1.8/
[root@dingzhi jdk1.8]# docker build -t jdk8.0.211:latest ./
-
1.5、验证jdk环境是否有安装成功
[root@dingzhi ~]# docker run -it c598 /bin/bash
[root@27dc649530b2 /]# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
[root@27dc649530b2 /]# javac -version
javac 1.8.0_211
(c598是docker images查看到jdk8.0.211:latest镜像的前4位id号)
第二步:创建tomcat8.5.40的镜像
-
2.1、下载tomcat8.5.40的tar包
(登录官网下载编译好的tomcat包)
[root@dingzhi ~]# cd tomcat8.5.40/
[root@dingzhi tomcat8.5.40]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.40/bin/apache-tomcat-8.5.40.tar.gz
#下载的gz包大小为9M
-
2.2、vim dockerfile
FROM jdk8.0.211:latest
MAINTAINER https://blog.csdn.net/lituxiu
ENV TIME_ZOME Asia/Shanghai
ADD apache-tomcat-8.5.40.tar.gz /usr/tomcat/
ENV CATALINA_HOME /usr/tomcat/apache-tomcat-8.5.40
ENV CATALINA_BASE $CATALINA_HOME
ENV PATH $PATH:$CATALINA_HOME/lib:$CATALINA_HOME/bin
RUN echo "${TIME_ZOME}" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/${TIME_ZOME} /etc/localtime
ENTRYPOINT /usr/tomcat/apache-tomcat-8.5.40/bin/catalina.sh run
-
2.3、创建tomcat8.5.40镜像
[root@dingzhi ~]# cd tomcat8.5.40/
[root@dingzhi tomcat8.5.40]# docker build -t tomcat8.5.40:latest ./
查看tomcat8.5.40镜像的id号
[root@dingzhi jdk1.8]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat8.5.40 latest 00640d3840d3 35 hours ago 622 MB
jdk8.0.211 latest c598103b2c55 37 hours ago 608 MB
nginx1.15.7 latest 4b05c87dcbec 46 hours ago 302 MB
php7.2.16 latest 3428fd528787 47 hours ago 627 MB
docker.io/mysql 5.7 98455b9624a9 3 weeks ago 372 MB
docker.io/centos latest 9f38484d220f 4 weeks ago 202 MB
-
2.4、验证:
[root@dingzhi jdk1.8]# docker run -p 8888:8080 --name tomcat8 -d 0064
查看是否正常运行
[root@dingzhi jdk1.8]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b9365c272f43 0064 "/bin/sh -c '/usr/..." 2 minutes ago Up 2 minutes 0.0.0.0:8888->8080/tcp tomcat8
在浏览器访问http://192.168.21.143:8888/
tomcat8.5.40镜像创建成功了!