自定义Tomcat9 镜像

  1. mkdir -p /wsh/mydockerfile/tomcat9
  2. 将jdk和tomcat安装的压缩包拷贝进新建的目录
    apache-tomcat-9.0.8.tar.gz
    jdk-8u171-linux-x64.tar.gz
  3. 在新建的目录下新建文件 help.txt
  4. 在/wsh/mydockerfile/tomcat9目录下新建Dockerfile文件
    内容:
FROM         centos
MAINTAINER    wsh<[email protected]>
#把宿主机当前上下文的c.txt拷贝到容器/usr/local/路径下
COPY help.txt /usr/local/cincontainer.txt
#把java与tomcat添加到容器中
ADD jdk-8u171-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-9.0.8.tar.gz /usr/local/
#安装vim编辑器
RUN yum -y install vim
#设置工作访问时候的WORKDIR路径,登录落脚点
ENV MYPATH /usr/local
WORKDIR $MYPATH
#配置java与tomcat环境变量
ENV JAVA_HOME /usr/local/jdk1.8.0_171
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.8
ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.8
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
#容器运行时监听的端口
EXPOSE  8080
#启动时运行tomcat
# ENTRYPOINT ["/usr/local/apache-tomcat-9.0.8/bin/startup.sh" ]
# CMD ["/usr/local/apache-tomcat-9.0.8/bin/catalina.sh","run"]
CMD /usr/local/apache-tomcat-9.0.8/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.8/bin/logs/catalina.out
  1. docker build -t wsh/tomcat9 .
  2. 构建完成,查看镜像是否生成
    docker images
  3. docker run -d -p 8080:8080 --name myt9 -v /wsh/mydockerfile/tomcat9/test:/usr/local/apache-tomcat-9.0.8/webapps/test -v /wsh/mydockerfile/tomcat9/tomcat9logs/:/usr/local/apache-tomcat-9.0.8/logs --privileged=true zzyytomcat9
    Docker挂载主机目录Docker访问出现cannot open directory .: Permission denied
    解决办法:在挂载目录后多加一个–privileged=true参数即可
  4. 验证
    http://localhost:8080

你可能感兴趣的:(Docker)