Dec 13, 2017

Docker-CE: Setting up a tomcat in less than a minute and running your JSP...

Last time i wrote about processes and files of a docker container hosting the docker example myapp.py.
Next step was to run a tomcat with a small application inside.

This can be done with theses commands:
  1. Get tomcat from the docker library:
    # docker pull tomcat
    Using default tag: latest
    latest: Pulling from library/tomcat
    3e17c6eae66c: Pull complete
    fdfb54153de7: Pull complete
    a4ca6e73242a: Pull complete
    5161d2a139e2: Pull complete
    7659b327f9ec: Pull complete
    ce47e69f11ad: Pull complete
    7d946df3a3d8: Pull complete
    a57cba73d797: Pull complete
    7e6f56cdb523: Pull complete
    06e4787b3ca5: Pull complete
    c760cb7e43cb: Pull complete
    ad6d0815df5c: Pull complete
    d7e1da09fc22: Pull complete
    Digest: sha256:a069d49c414bad0d98f5a4d7f9b7fdd318ccc451dc535084480c8aead68272d2
    Status: Downloaded newer image for tomcat:latest
  2. Test the tomcat:
    # docker run -p 4000:8080 tomcat
    20-Nov-2017 20:38:11.754 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.23
    20-Nov-2017 20:38:11.762 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Sep 28 2017 10:30:11 UTC
    20-Nov-2017 20:38:11.762 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.23.0
    ....
    ....
    org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
    20-Nov-2017 20:41:59.928 INFO [Thread-5] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]
     

This was easy.
Now create your JSP and run it:
  1. create a directory
    mkdir tomcatstatus
  2. create a jsp inside this direcotry
    vi tomcatstatus/index.jsp
    and insert the following content:
    <%@ page language="java" import="java.util.*" %>


    Host name : <%=java.net.InetAddress.getLocalHost().getHostName() %>

    Server Version: <%= application.getServerInfo() %>

    Servlet Version: <%= application.getMajorVersion() %>.<%= application.getMinorVersion(
    ) %>
    JSP Version: <%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersio
    n() %>
  3. Run docker
    docker run -v /home/schroff/tomcatstatus:/usr/local/tomcat/webapps/status -p 4000:8080 tomcat
  4. Connect to port 4000:

Wow - i am really stunned how fast the tomcat was setup and the jsp was launched. No installation of java (ok, this is only apt install) and no setup procedure for Apache tomcat (ok, this is just a tar -zxvf). But if i want to run more than one installation - docker is faster than repeating the installation or copying files.  Really cool!


(One thing i forgot: Installation of docker onto your server)

Related posts:

No comments:

Post a Comment