# 准备材料

apache-tomcat gz 包

jdk gz 包

# 构建文件目录存放操作数据

ZHIXING 11:10 tomcat9\pwd
/opt/docker/tomcat9
ZHIXING 11:10 tomcat9\ll
总用量 193924
-rw-r--r--. 1 root    root     10982406 1027 08:09 apache-tomcat-9.0.16.tar.gz
-rw-r--r--. 1 root    root          623 1027 11:05 Dockerfile
-rw-r--r--. 1 root    root    187579428 1027 08:12 jdk1.8.0_19.tar.gz
-rw-r--r--. 1 root    root            0 1027 11:05 test.txt

# 文件信息介绍

apache-tomcat-9.0.27.tar.gz tomcat包

jdk1.8.tar.gz jdk 包

test.txt 测试复制命令

Dockerfile 构建镜像的代码集

# Dockerfile 内容如下

关键字介绍

FROM centos:latest
MAINTAINER ZHIXING<xxxxxxxx.com>

COPY test.txt /usr/local/testincontainer.txt

ADD apache-tomcat-9.0.16.tar.gz /usr/local
ADD jdk1.8.0_191.tar.gz /usr/local
RUN yum -y install vim

ENV MYPATH /usr/local

WORKDIR $MYPATH

ENV JAVA_HOME /usr/local/jdk1.8.0_191
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.16
ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.16
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin

VOLUME /home

EXPOSE 8080

CMD /usr/local/apache-tomcat-9.0.16/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.16/logs/catalina.out

# 构建镜像

docker build -f /opt/docker/tomcat9/Dockerfile -t mytomcat9 .

# 验证镜像

# 查看本地镜像

ZHIXING 11:13 tomcat9\docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mytomcat9           latest              a1c3edd61706        18 seconds ago      678MB

# 启动镜像

docker run -d -p 8080:8080 --name mytomcat9 \
-v /opt/docker/tomcat9/data/test:/usr/local/apache-tomcat-9.0.16/webaps/test \
-v /opt/docker/tomcat9/data/tomcatlogs:/usr/local/apache-tomcat-9.0.16/logs mytomcat9

# 查看日志

# 访问浏览器 ip + port

精彩内容推送,请关注公众号!
最近更新时间: 4/16/2020, 7:39:00 PM