构建tomcat镜像
- 创建工作目录
[root@elk-node2 tomcat]# mkdir tomcat
[root@elk-node2 tomcat]# cd tomcat
[root@elk-node2 tomcat]# ls
apache-tomcat-8.5.16.tar.gz jdk1.8.0_191 jdk-8u191-linux-x64.tar.gz
- 创建Dockfile 文件
FROM centos:latest
#维护该镜像的用户信息
MAINTAINER abc abc@163.com
#安装JDK环境,设置其环境变量
#RUN tar zxf jdk-8u191-linux-x86.tar.gz
ADD jdk1.8.0_191 /usr/local/jdk-8u191
ENV JAVA_HOME /usr/local/jdk-8u191
ENV JAVA_BIN /usr/local/jdk-8u191/bin
ENV JRE_HOME /usr/local/jdk-8u191/jre
ENV PATH $PATH:/usr/local/jdk-8u191/bin:/usr/local/jdk-8u191/jre/bin
ENV CLASSPATH /usr/local/jdk-8u191/jre/bin:/usr/local/jdk-8u191/lib:/usr/local/jdk-8u191/jre/lib/charsets.jar
#解压tomcat 并移动到响应位置
ADD apache-tomcat-8.5.16.tar.gz /usr/local/tomcat
#开启8080
- 用Dockerfile 生成镜像
[root@elk-node2 tomcat]# docker build -t tomcat:centos .
- 运行容器并验证
映射本地8080端口到容器的8080端口
[root@elk-node2 tomcat]# docker run -itd -p 8080:8080 tomcat:centos bash
812e52048354900515378927488e01206e39454ea2be732f39a428b10360fa6f
进入运行的容器,启动tomcat
[root@elk-node2 tomcat]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
812e52048354 tomcat:centos "bash" 53 seconds ago Up 46 seconds 0.0.0.0:8080->8080/tcp clever_snyder
[root@elk-node2 tomcat]# docker exec -it 812 bash
[root@812e52048354 /]# /usr/local/tomcat/apache-tomcat-8.5.16/bin/startup.sh
Tomcat started.
[root@812e52048354 /]# exit
exit
[root@elk-node2 tomcat]# curl 192.168.30.25:8080
<!DOCTYPE html>
<html lang="en">
<head>