Upgrade to Pro — share decks privately, control downloads, hide ads and more …

wjax2014: Docker Tomcat Microservices

wjax2014: Docker Tomcat Microservices

**Tomcat and Docker: The base of your microservices**

Here you can find my docker slide deck container of my [WJAX 2014 - GER: Tomcat als Basis deiner Microservices-Anwendungen][1] talk.

- start with `docker run -tid -p 8006:80 rossbachp/docker-tomcat-micro:wjax2014`
- open your browser with `http :8006/docker-tomcat-micro`
- view english slides [Tomcat and Docker: The base of your microservices][2]

Feedback welcome

[Peter Rossbach][3]

[1]: https://jax.de/wjax2014/sessions/tomcat-als-basis-deiner-microservices-anwendungen
[2]: https://speakerdeck.com/rossbachp/wjax2014-docker-tomcat-microservices
[3]: https://twitter.com/PRRossbach

Peter Rossbach

November 19, 2014
Tweet

More Decks by Peter Rossbach

Other Decks in Programming

Transcript

  1. 20 / 48 © 2014 <[email protected]>, @PRossbach, WJAX Munich public

    void start() throws ServletException, LifecycleException,MalformedURLException { String webappDirLocation = "."; Tomcat tomcat = new Tomcat(); String webPort = getConfigParameter( CONFIG_SERVICE_PORT, "8080"); tomcat.setPort(Integer.valueOf(webPort)); Context context = tomcat.addWebapp("/hello", new File( webappDirLocation).getAbsolutePath()); Tomcat.addServlet(context, "jersey-container-servlet", resourceConfig()); context.addServletMapping("/rest/*", "jersey-container-servlet"); AccessLogStdoutValve valve = new AccessLogStdoutValve(); String pattern = getConfigParameter( CONFIG_SERVICE_PATTERN, ACCESS_LOG_PATTERN); valve.setPattern(pattern); context.getPipeline().addValve(valve); tomcat.start(); tomcat.getServer().await(); }
  2. 22 / 48 © 2014 <[email protected]>, @PRossbach, WJAX Munich FROM

    bee42/java:jre-8 MAINTAINER Peter Rossbach <[email protected]> RUN mkdir /opt/micro COPY target/helloworld.jar /opt/micro/helloworld.jar COPY micro.sh /opt/micro/micro.sh COPY logging.properties /opt/micro/logging.properties WORKDIR /opt/micro EXPOSE 8080 EXPOSE 8009 CMD [ "/bin/bash", "-c", "/opt/micro/micro.sh" ]
  3. 23 / 48 © 2014 <[email protected]>, @PRossbach, WJAX Munich #!/bin/bash

    java -Duser.language=en\ -Duser.country=US\ -Dava.util.logging.config.file=/opt/micro/logging.properties\ -Djava.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$tdT%1$tH:%1 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager\ -Djava.security.egd=file:/dev/./urandom\ -jar helloworld.jar
  4. 24 / 48 © 2014 <[email protected]>, @PRossbach, WJAX Munich handlers

    = java.util.logging.ConsoleHandler .handlers = java.util.logging.ConsoleHandler .level=INFO java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$tdT%1$tH:%1$tM:%1$tS.% org.apache.tomcat.util.digester.Digester.level=OFF org.apache.jasper.level=INFO org.apache.jasper.servlet.TldScanner.level=WARNING org.apache.catalina.startup.ContextConfig.level=WARNING
  5. 25 / 48 © 2014 <[email protected]>, @PRossbach, WJAX Munich $

    docker build -t="rossbachp/helloworld" . $ docker run -dit -p 8000:8080 rossbachp/helloworld $ curl -s http://192.168.59.103:8000/hello/rest/helloworld Hello World from Tomcat Embeded with Jersey! $ docker login $ docker push rossbachp/helloworld
  6. 26 / 48 © 2014 <[email protected]>, @PRossbach, WJAX Munich $

    curl -s http://192.168.59.103:8000/hello/rest/status <html> <body> <h1>Docker Tomcat status page</h1> <ul> <li>Hostname : 5365ac28dc4b</li> <li>Now : 2014/11/03 13:21:51</li> </ul> </body> </html>
  7. 27 / 48 © 2014 <[email protected]>, @PRossbach, WJAX Munich FROM

    debian:7.6 MAINTAINER Peter Rossbach <[email protected]> RUN \ echo "deb http://ftp.us.debian.org/debian sid main" >> /etc/apt/sources.list && \ apt-get update -yq && apt-get install -yqq openjdk-8-jre-headless=8u40~b09-1 wget=1.15-1+b1 \ unzip=6.0-12 && \ apt-get clean autoclean && \ apt-get autoremove -y && \ rm -rf /var/lib/{apt,dpkg,cache,log}/ CMD /bin/bash docker build -t="bee42/java:jre-8" .
  8. 32 / 48 © 2014 <[email protected]>, @PRossbach, WJAX Munich $

    docker run -d --name redis.0 -p 10000:6379 \ -e "SERVICE_NAME=db" \ -e "SERVICE_TAGS=master,backups" \ -e "SERVICE_REGION=us2" dockerfile/redis { "ID": "hostname:redis.0:6379", "Name": "db", "Port": 10000, "IP": "192.168.1.102", "Tags": ["master", "backups"], "Attrs": {"region": "us2"} }
  9. 33 / 48 © 2014 <[email protected]>, @PRossbach, WJAX Munich docker

    run -d -p 8007:80 rossbachp/scale-tomcat- deck:wjax2014 open http://<dockerhost>:8007/scale-tomcat- deck:wjax2014
  10. 47 / 48 © 2014 <[email protected]>, @PRossbach, WJAX Munich docker

    run -d -p 8008:80 rossbachp/docker-tomcat-micro:wjax2014 http <dockerhost>:8008/docker- tomcat-micro