Docker中使用Tomcat8

需求:在CentOS7中安装Tomcat8+JDK1.8
前提:准备好jdk-8u101-linux-x64.tar.gz和Tomcat8.tar.gz
放在/opt/test/lixr目录中

  1. 启动docker中CentOS7容器
[root@wxtest1607 lixr]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
centos                    7.2.1511            686672a1d0cc        7 weeks ago         194.6 MB
[root@wxtest1607 lixr]# docker run -i -t -v /opt/test/lixr/:/mnt/software 6866 /bin/bash
#将本机的/opt/test/lixr/目录挂载到容器/mnt/software目录
[root@d781b762b19a /]# 
  1. 安装jdk 和 tomcat
#将jdk和tomcat 安装到/opt/product/tools目录
#mdkir -p /opt/product/tools/
#解压缩内容到/opt/product/tools
[root@d781b762b19a tools]# ls -lh
total 4.0K
drwxr-xr-x 8 root root 4.0K Aug 23 11:12 jdk1.8.0_101
drwxr-xr-x 9 root root  149 Aug 23 11:12 tomcat8
  1. 配置启动tomcat
touch tomcatrun.sh
文件内容
#!/bin/bash
export JAVA_HOME=/opt/product/tools
export PATH=$JAVA_HOME/bin:$PATH
sh /opt/product/tools/tomcat8/bin/catalina.sh run
chmod +x tomcatrun.sh
  1. 提交新镜像
[root@wxtest1607 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
d781b762b19a        6866                "/bin/bash"         14 minutes ago      Exited (0) 13 seconds ago                       goofy_bartik
[root@wxtest1607 ~]# docker commit d781 tomcat8:1.0
[root@wxtest1607 ~]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
tomcat8                   1.0                 aa795b596e71        20 seconds ago      601.1 MB
  1. 启动tomcat
[root@wxtest1607 ~]# docker run -d -p 58080:8080 aa79 /root/tomcatrun.sh
8122ab04139aa13358358fefcb77bf76c49cca0119f3680c440820336ad44c30
  1. 访问tomcat
    http://192.168.220.123:58080/docs/
    原文作者:灼灼2015
    原文地址: https://www.jianshu.com/p/22ea93261cc6
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞