(Docker notes): Actual combat-Tomcat mirroring (to be continued)

 

Actual combat: Tomcat mirroring

  • 1. Prepare the image file tomcat compression package, jdk compression package

  • 2. Write a dockerfile file, officially named Dockerfile , build will automatically find this file, no need to specify -f

FROM centos   # 基本镜像
MAINTAINER Aut<[email protected]>    # 作者信息

COPY readme.txt /usr/local/readme.txt    # 复制readme到容器内部的这个路径

ADD /home/dockerfile/jdk-8u11-linux-x64.tar.gz /usr/local/    # ADD 命令会自动解压 将tar包解压到这个路径
ADD /home/dockerfile/apache-tomcat-9.0.22.tar.gz /usr/local/

RUN yum -y install vim    # 安装一些基本命令

ENV MYPATH /usr/local     # 设置默认的工作目录
WORKDIR $MYPATH

ENV JAVA_HOME /usr/local/jdk1.8.0_11    # java 环境变量
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/toos.jar

ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.22    # tomcat 环境变量
ENV CATALINA_BASH /usr/local/apache-tomcat-9.0.22
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin

EXPOSE 8080  # 暴露 tomcat 端口

CMD /usr/local/apache-tomcat-9.0.22/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.22/bin/logs/catalina.out  # 启动 tomcat 可以通过 && 拼接一些参数  tail -F 显示文件新追加的内容
  • 3. Build the image, the file is named Dockerfile, and then you can specify the file without -f, which can automatically match

  • 4. Run after build
docker run -d -p 9090:8080 --name testtomcat -v /home/tomcat/test:/usr/local/apache-tomcat-9.0.22/webapps diytomcat

  • 5. Access test: enter the container to view the directory
docker exec -it 容器id /bin/bash
  • 6. Publish the project, mount the webapps directory in a directory on the host machine, so you can directly write the project locally
  • 7. Visit the application in the tomcat server and test to see if it is successful

Guess you like

Origin blog.csdn.net/baidu_41388533/article/details/108566662
Recommended