• Docker(十一):Docker实战部署HTTPS的Tomcat站点


    1、选择基础镜像

       docker pull tomcat:7.0-jre8

    2、生成HTTPS证书

      keytool -genkey -alias tomcat -keyalg RSA -keystore tomcat.keystore

      root@HX-StrMedia:~/ssl# ls
      tomcat.keystore

    3、启动tomcat容器并导入证书

      root@7632c9d5c82b:/usr/local/tomcat# ls /tmp/
      tomcat.keystore
      root@7632c9d5c82b:/usr/local/tomcat# mkdir keys
      root@7632c9d5c82b:/usr/local/tomcat# cp /tmp/tomcat.keystore keys/
      root@7632c9d5c82b:/usr/local/tomcat# ls keys/
      tomcat.keystore

      修改配置文件如下:

        <Connector port="8443" protocol="HTTP/1.1"
        maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
        clientAuth="false" sslProtocol="TLS"
        keystoreFile="/usr/local/tomcat/keys/tomcat.keystore"
        keystorePass="dukuan" />

      也可配置8080 端口

        <Connector port="8080" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443"
        SSLEnabled="true" scheme="https" secure="true"
        clientAuth="false" sslProtocol="TLS"
        keystoreFile="/usr/local/tomcat/keys/tomcat.keystore"
        keystorePass="dukuan"
        />

    4、Commit

      不退出容器在宿主机commit

      root@HX-StrMedia:~/ssl# docker ps -a
      CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
      d3a3c7964a89 tomcat:7.0-jre8 "bash" 28 seconds ago Up 26 seconds 8080/tcp determined_mahavira

      root@HX-StrMedia:~/ssl# docker commit d3a3c7964a89 tomcat:https

      root@HX-StrMedia:~/ssl# docker images;
      REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
      tomcat https 5308378959ab About a minute ago 560.8 MB

    5、启动并访问

      root@HX-StrMedia:~/ssl# docker run --rm -ti -p 9099:8080 tomcat:https

      root@HX-StrMedia:~/ssl# docker ps
      CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
      532a4ef7efcc tomcat:https "bash" 29 seconds ago Up 29 seconds 0.0.0.0:9099->8080/tcp thirsty_bhaskara

       访问宿主机9099端口即可

    6、将web源码部署到Tomcat镜像中

      6.1 静态导入

        创建Dockerfile如下,将websrc下的源码复制到webapps下

          # cat Dockerfile
          # This is Dockerfile
          # Version 1.0
          # Author is Dukuan

          # 第一行必须指定基于的基础镜像
          FROM centos

          # 维护者信息
          MAINTAINER Du Kuan

          FROM tomcat:https

          COPY ./websrc /usr/local/tomcat/webapps/myproj/  

          # docker build -t myweb:v1 .
          Sending build context to Docker daemon 3.072 kB
          Step 1 : FROM centos
          ---> d4350798c2ee
          Step 2 : MAINTAINER Du Kuan
          ---> Running in cd053280ea4f
          ---> 687ac7bd642f
          Removing intermediate container cd053280ea4f
          Step 3 : FROM tomcat:https
          ---> 71400c2da356
          Step 4 : COPY ./websrc /usr/local/tomcat/webapps/myproj/
          ---> f704dc9f0466
          Removing intermediate container 4fd43be2f210
          Successfully built f704dc9f0466

          # docker images
          REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
          myweb v1 f704dc9f0466 7 minutes ago 560.8 MB
          tomcat https 71400c2da356 4 hours ago 560.8 MB

      6.2 静态挂载

        创建Dockerfile

        # This is Dockerfile
        # Version 1.0
        # Author is Dukuan

        # 第一行必须指定基于的基础镜像
        FROM tomcat:https

        # 维护者信息
        MAINTAINER Du Kuan

        RUN mkdir -p /usr/local/tomcat/webapps/myproj

        # 表示在镜像中创建一个挂载点
        VOLUME /usr/local/tomcat/webapps/myproj

        创建镜像

        docker build -t myweb:v2 .

        启动镜像

        docker run -ti -v $(pwd)/../websrc:/usr/local/tomcat/webapps/myproj myweb:v2

        主机修改文件

        echo "This is page" >> index.jsp

        查看容器是否修改  

        root@4899f6c92448:/usr/local/tomcat# cat webapps/myproj/index.jsp
        Test Page
        This is page

        

  • 相关阅读:
    转移阵地啦
    春之感--3月10日
    小鱼儿
    关于时间方法(date和simpledateformat)的实验
    hadoop练习处理地震数据
    出现log4j.properties问题
    远程hadoop集群方法
    小W学物理
    灵知的太阳信仰
    Blue
  • 原文地址:https://www.cnblogs.com/dukuan/p/7667807.html
Copyright © 2020-2023  润新知