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

Microxchg2015 Docker Tomcat and Microservices

Microxchg2015 Docker Tomcat and Microservices

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

Here you can find my docker slide deck container of my talk.

- [microxchg conference Berlin 2015 - Docker, Tomcat and Microservices ][3].
- open slidefire presentation container with `docker run -d -p 8000:80 rossbachp/docker-tomcat-micro`:microxchg2015`
- pdf [Docker, Tomcat and Microservices][4] is now avaiable!
- [WJAX 2014 - GER: Tomcat als Basis deiner Microservices-Anwendungen][1]
- [Tomcat and Docker: The base of your microservices][2]
- start with `docker run -d -p 8001:80 rossbachp/docker-tomcat-micro:wjax2014`
- open your browser with `http :8001/docker-tomcat-micro`

Feedback welcome

[Peter Rossbach][5]

[1]: https://jax.de/wjax2014/sessions/tomcat-als-basis-deiner-microservices-anwendungen
[2]: https://speakerdeck.com/rossbachp/wjax2014-docker-tomcat-microservices
[3]: http://microxchg.io/talk/peter_rossbach_microservices_mit_docker_und_apache_tomcat.html
[4]: https://speakerdeck.com/rossbachp/microxchg2015-docker-tomcat-and-microservices
[5]: https://twitter.com/PRRossbach

Peter Rossbach

February 17, 2015
Tweet

More Decks by Peter Rossbach

Other Decks in Programming

Transcript

  1. 22 / 61 © 2015 <[email protected]>, @PRossbach, microxchg 2015 berlin

    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. 24 / 61 © 2015 <[email protected]>, @PRossbach, microxchg 2015 berlin

    FROM infrabricks/java:openjre-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 CMD [ "/bin/bash", "-c", "/opt/micro/micro.sh" ] docker build -t="infrabricks/tomcat:8" .
  3. 25 / 61 © 2015 <[email protected]>, @PRossbach, microxchg 2015 berlin

    FROM debian:8 MAINTAINER Peter Rossbach <[email protected]> ENV DEBIAN_FRONTEND noninteractive RUN \ echo "deb http://ftp.us.debian.org/debian sid main" >> /etc/apt/sources.list \ && apt-get update \ && apt-get install -yq openjdk-8-jre-headless \ wget\ pwgen\ && apt-get clean autoclean \ && apt-get autoremove -y \ && rm -rf /var/lib/{apt,dpkg,cache,log}/ ... docker build -t="infrabricks/java:openjre-8" .
  4. 26 / 61 © 2015 <[email protected]>, @PRossbach, microxchg 2015 berlin

    #!/bin/bash java -Duser.language=en\ -Duser.country=US\ -DCOUCHDB_HOST=couchdb \ -Djava.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
  5. 27 / 61 © 2015 <[email protected]>, @PRossbach, microxchg 2015 berlin

    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
  6. 28 / 61 © 2015 <[email protected]>, @PRossbach, microxchg 2015 berlin

    $ mvn package $ docker build -t="infrabricks/helloworld" . $ docker run -dit -p 8000:8080 infrabricks/helloworld $ curl -s http://192.168.59.103:8000/hello/rest/helloworld Hello World from Tomcat Embeded with Jersey! $ docker login $ docker push infrabricks/helloworld
  7. 29 / 61 © 2015 <[email protected]>, @PRossbach, microxchg 2015 berlin

    $ 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>
  8. 34 / 61 © 2015 <[email protected]>, @PRossbach, microxchg 2015 berlin

    $ 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. 38 / 61 © 2015 <[email protected]>, @PRossbach, microxchg 2015 berlin

    cd docker-d/hello docker-compose up -d docker-compose scale tomcat=3 status: build: . tomcat: image: infrabricks/tomcat:8 ports: - "8080" volumes_from: - status volumes: - tomcat-users.xml:/opt/tomcat/conf/tomcat-users.xml environment: constraint: zone==dev constraint: disk==ssd SERVICE_8080_NAME: status_http SERVICE_8009_NAME: status_ajp SERVICE_TAGS: tomcat SERVICE_REGION: bee42.1
  10. 39 / 61 © 2015 <[email protected]>, @PRossbach, microxchg 2015 berlin

    cd docker.d docker-compose -f master.yml up -d consul: build: consul ports: - "8400:8400" - "8500:8500" - "8600:53/udp" command: -bootstrap registrator: build: registrator links: - consul:consul volumes: - /var/run/docker.sock:/tmp/docker.sock command: -internal consul://consul:8500/services lb: build: nginx-lb ports: - "80:80" links: - consul:consul
  11. 59 / 61 © 2015 <[email protected]>, @PRossbach, microxchg 2015 berlin

    docker run -d -p 8000:80 rossbachp/docker-tomcat-micro:microxchg2015 http <dockerhost>:8000/docker- tomcat-micro