1.Dockerfile脚本

需要下载两个包
apache-tomcat-9.0.8.tar.gz
jdk-8u171-linux-x64.tar.gz

  1. FROM centos
  2. MAINTAINER zzyy<zzyybs@126.com>
  3. #把宿主机当前上下文的c.txt拷贝到容器/usr/local/路径下
  4. COPY c.txt /usr/local/cincontainer.txt
  5. #把java与tomcat添加到容器中
  6. ADD apache-tomcat-9.0.41.tar.gz /usr/local/
  7. ADD jdk-8u281-linux-x64.tar.gz /usr/local/
  8. #安装vim编辑器
  9. RUN yum -y install vim
  10. #设置工作访问时候的WORKDIR路径,登录落脚点
  11. ENV MYPATH /usr/local
  12. WORKDIR $MYPATH
  13. #配置java与tomcat环境变量
  14. ENV JAVA_HOME /usr/local/jdk1.8.0_171
  15. ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  16. ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.41
  17. ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.41
  18. ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
  19. #容器运行时监听的端口
  20. EXPOSE 8080
  21. #启动时运行tomcat
  22. #ENTRYPOINT ["/usr/local/apache-tomcat-9.0.41/bin/startup.sh"]
  23. #CMD["/usr/local/apache-tomcat-9.0.41/bin/catalina.sh" ,"run"]
  24. CMD /usr/local/apache-tomcat-9.0.41/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.41/bin/logs/catalina.out

2.创建镜像

  1. root@test mydocker]# docker build -f /mydocker/tomcatfile -t tomcat2 .
  2. Sending build context to Docker daemon 155.2MB
  3. Step 1/15 : FROM centos
  4. ---> 300e315adb2f
  5. Step 2/15 : MAINTAINER zzyy<zzyybs@126.com>
  6. ---> Using cache
  7. ---> e1b1d7522039
  8. Step 3/15 : COPY c.txt /usr/local/cincontainer.txt
  9. ---> Using cache
  10. ---> 7059c680c735
  11. Step 4/15 : ADD apache-tomcat-9.0.41.tar.gz /usr/local/
  12. ---> Using cache
  13. ---> b236dc34677b
  14. Step 5/15 : ADD jdk-8u281-linux-x64.tar.gz /usr/local/
  15. ---> Using cache
  16. ---> 6edeaf32e67c
  17. Step 6/15 : RUN yum -y install vim
  18. ---> Using cache
  19. ---> f098797c0ca1
  20. Step 7/15 : ENV MYPATH /usr/local
  21. ---> Using cache
  22. ---> adf68f1a8b4e
  23. Step 8/15 : WORKDIR $MYPATH
  24. ---> Using cache
  25. ---> f5a51782665b
  26. Step 9/15 : ENV JAVA_HOME /usr/local/jdk1.8.0_171
  27. ---> Using cache
  28. ---> 67e366964602
  29. Step 10/15 : ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  30. ---> Using cache
  31. ---> 8ad4eabe3b0c
  32. Step 11/15 : ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.41
  33. ---> Using cache
  34. ---> 8e0b7f86c73d
  35. Step 12/15 : ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.41
  36. ---> Using cache
  37. ---> fd62c1c27136
  38. Step 13/15 : ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
  39. ---> Using cache
  40. ---> 736cbb5b652f
  41. Step 14/15 : EXPOSE 8080
  42. ---> Using cache
  43. ---> 6f46b5bea76a
  44. Step 15/15 : CMD /usr/local/apache-tomcat-9.0.41/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.41/bin/logs/catalina.out
  45. ---> Running in b035d3acf741
  46. Removing intermediate container b035d3acf741
  47. ---> b18d544aa0b6
  48. Successfully built b18d544aa0b6
  49. Successfully tagged tomcat2:latest

3. 运行镜像并绑定容器卷

  1. [root@test mydocker]# docker run -d -p 9080:8080 --name mytomcat2 -v /root/mydockerfile/tomcat9/test:/usr/local/apache-tomcat-9.0.41/webapps/test -v /root/mydockerfile/tomcat9/tomcat9logs/:/usr/local/apache-tomcat-9.0.41/logs --privileged=true tomcat2

4.需要学习 linux下搭建一个apache+jdk环境需要什么版本