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

Docker in der Java-Entwicklung

Docker in der Java-Entwicklung

Talk at First Docker@Dresden-Meetup 2015-11-19

berndfischer63

November 19, 2015
Tweet

More Decks by berndfischer63

Other Decks in Programming

Transcript

  1. Who’s that guy? Passionate Java Developer (especially Spring) Agile and

    Devops infected Docker enthusiast [email protected] @berndfischer63 JUG Saxony e.V., Docker Meetup Dresden CTO MindApproach GmbH, Dresden [email protected]
  2. Who’s that guy? You build it you run it Werner

    Vogels, CTO Amazon, 2006 [Gra01]
  3. What is Docker? Virtualization Virtual Machine Hypervisor / Host OS

    Physical Server Physical Server Host OS App A App B Libs Libs Guest OS Virtual Hardware / BIOS Docker Engine Container (Process) App A Libs Container App A Libs Container VirtualMachine
  4. What is Docker? Used Technologies Docker Libcontainer Namespaces Control Groups

    Storage Backends Layered/CoW Filesystems Linux Kernel Software Defined Networking
  5. What is Docker? Storage Backends read only writable empty after

    creation many containers can be created based on one image for specific requirements: use volumes https://www.docker.com/sites/default/files/products/what_is_layered_filesystems_sm.png Images and Container
  6. What is Docker? System Architecture Docker Host (Linux) Docker Client

    Docker Daemon Container Images Container Container Images Images Socket RESTFul API Docker Client Windows Docker Client Mac OS V Docker Client
  7. What is Docker? Docker Project Family • Docker-Engine (CLI +

    Daemon) • Docker-Machine • Docker-Compose • (Docker-Swarm) • (Docker-Distribution) • (Docker-Toolbox) • (Docker Notary based on TUF) • (Docker-Bench-Security)
  8. What is Docker? Development Environment Virtual Machine (Linux) Images Container

    Mac OS X Windows /Users /Users Docker Client Docker Daemon
  9. What is Docker? Summary • Process-Virtualization ◦ OS-/Architecture-Specific • Layered-Filesystem

    (Images/Container) • Public/Private Registries (Dockerhub) • Project-Family ◦ batteries included ◦ but replaceable
  10. Dockerize a Java Web App Starting Point Linux (Ubuntu 14.04.3-LTS)

    java -jar ... url username password JVM Demo-Application Spring Boot Web embedded Tomcat Database
  11. Dockerize a Java Web App MySql - Container Docker Machine

    docker-machine \ create \ --driver=virtualbox \ dev
  12. Dockerize a Java Web App MySql - Container Docker Compose

    # s01-docker-compose.yaml mysql: image: mysql:5.6.26 expose: - "3306" ports: - "3306:3306" environment: - MYSQL_ROOT_PASSWORD=9876 - MYSQL_USER=test - MYSQL_PASSWORD=1234 - MYSQL_DATABASE=test
  13. Dockerize a Java Web App Java - Container # s02-docker-compose.yaml

    (snippet) app: image: java:8 ports: - "8080:8080" environment: - SPRING_PROFILES_ACTIVE=initdb working_dir: /opt/demo-helloworld-web links: - mysql:mysql entrypoint: [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/opt/demo-helloworld-web/demo-helloworld-web-1.0-Local.jar" ] volumes: - ../../../target:/opt/demo-helloworld-web:ro
  14. Dockerize a Java Web App Unpacked Fat-Jar # maven -PunzipFatJar

    # unzip target/demo-helloworld-web-1.0-Local.jar \ -d target/app # s03-docker-compose.yaml (snippet) app: # ... volumes: - ../../../target/app/META-INF:/opt/.../META-INF:ro - ../../../target/classes/de:/opt/.../de:ro - ../../../target/app/lib:/opt/.../lib:ro - ../../../target/app/org:/opt/.../org:ro - ../../../target/classes/static:/opt/.../static:ro - ../../../target/classes/templates:/opt/.../templates:ro - ../../../target/classes/application.yml:/opt/.../application.yml:ro - ../../../target/classes/logback.xml:/opt/.../logback.xml:ro
  15. Dockerize a Java Web App Docker Image by Foot #

    Dockerfile FROM java:8 MAINTAINER Bernd Fischer "[email protected]" ENV MODIFIED_AT 2015-09-26_1845 COPY demo-helloworld-web.jar /opt/demo-helloworld-web/ # mvn -PbuildDockerWorkDir # copy Dockerfile and “Fat-Jar” in same dir # should be called from project root dir docker build -t mapp/demo-helloworld-web04:latest \ -f $(pwd)/target/workdir-docker/Dockerfile \ $(pwd)/target/workdir-docker
  16. Dockerize a Java Web App Docker Image by Foot #

    s04-docker-compose.yaml (snippet) app: image: mapp/demo-helloworld-web04:latest ports: - "8080:8080" environment: - SPRING_PROFILES_ACTIVE=initdb working_dir: /opt/demo-helloworld-web/ links: - mysql:mysql entrypoint: [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar","/opt/demo-helloworld-web/demo-helloworld-web.jar" ] _________
  17. Dockerize a Java Web App Docker Image by Maven (1)

    # Maven (snippet) <plugin> <groupId>org.jolokia</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.13.4</version> <configuration> <dockerHost>${env.DOCKER_HOST}</dockerHost> <certPath>${env.DOCKER_CERT_PATH}</certPath> <images> <image> <name>mapp/demo-helloworld-web05</name> ... </image> </images> </configuration> ... </plugin>
  18. Dockerize a Java Web App Docker Image by Maven (2)

    # Maven (snippet) <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.3.5</version> <configuration> <imageName>mapp/demo-helloworld-web07</imageName> <imageTags> <imageTag>${project.version}</imageTag> </imageTags> <dockerDirectory>${project.basedir}/target/app</dockerDirectory> <forceTags>true</forceTags> </configuration> </plugin>
  19. Dockerize a Java Web App Docker Image by Maven #

    s07-docker-compose.yaml (snippet) app: image: mapp/demo-helloworld-web07:latest ports: - "8080:8080" environment: - SPRING_PROFILES_ACTIVE=initdb working_dir: /opt/demo-helloworld-web/ links: - mysql:mysql entrypoint: [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar","/opt/demo-helloworld-web/demo-helloworld-web.jar" ]
  20. Dockerize a Java Web App Docker Push (Registry) docker tag

    ... docker login ... docker push ...
  21. Dockerize a Java Web App Docker Push by Maven mvn

    clean package -DskipTests=true \ -PunzipFatJar \ -PbuildDockerImageWithSpotifyAndPushToDockerhub \ -DpushImage=true \ docker:build
  22. Dockerize a Java Web App Docker Push by Maven <!--

    maven.pom (snippet) --> <profile><id>buildDockerImageWithSpotifyAndPushToDockerhub</id> <build> <plugins><plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.3.5</version> <configuration> <imageName>mapp/demo-helloworld-web07</imageName> <imageTags><imageTag>${project.version}</imageTag></imageTags> <dockerDirectory>${project.basedir}/target/app</dockerDirectory> <forceTags>true</forceTags> <serverId>docker-hub</serverId> </configuration> </plugin></plugins> </build></profile>
  23. Dockerize a Java Web App Docker & Jenkins Workflow def

    internalBuild(){ stage name: "build", concurrency: 1 node{ sh "${mvnHome}/bin/mvn clean" sh "${mvnHome}/bin/mvn pl.project13.maven:git-commit-id-plugin:revision sh "${mvnHome}/bin/mvn package -U -PbuildDockerImageWithMaven" def dcmd = "docker -H \${DOCKER_HOST_STRIPPED} --tlsverify" sh "${dcmd} tag -f \${DOCKER_FORCE_TAGGING} \ mapp/demo-helloworld-web05:${newVersion} \ dockerreg:5000/mapp/demo-helloworld-web05:${newVersion}" sh "${dcmd} push \ \${DOCKER_REGISTRY}/mapp/demo-helloworld-web05:${newVersion}" } }
  24. Dockerize a Java Web App Production - IaaS DEMO -

    Digital Ocean (online access necessary ;-)
  25. Dockerize a Java Web App Production - PaaS GiantSwarm •

    currently public beta … // swarm.json [snippet] { "name": "demo-helloworld-web05", "components": { "app": { "image": "mapp/demo-helloworld-web05:latest", ... }, "mysql": { "image": "mysql:5.6.26", ... }}}
  26. Dockerize a Java Web App Production - PaaS GiantSwarm •

    Images expected in Dockerhub or GiantSwarm own private registry # own CLI swarm login swarm ls swarm create swarm start / swarm stop swarm status swarm logs swarm logout
  27. Dockerize a Java Web App Production - PaaS DEMO -

    Giant Swarm (online access necessary ;-)
  28. Dockerize a Java Web App Production - PaaS • Amazon

    Container Services • Google Container Services (Kubernetes) • Profitbricks • Joyent (Triton) • Cloudfoundry (Warden) ◦ Pivotal ◦ IBM Bluemix • Redhat Openshift
  29. Dockerize a Java Web App Production - PaaS OnPremis On

    Premise • IaaS as base • Docker Swarm • Redhat Atomic / Openshift • Kubernetes • Mesos • DEIS • Rancher (based on RancherOS) • ….
  30. Lessons Learned Bereitstellung von Tools und Komponenten Verpacken und Deployen

    von Anwendungen Einfache Definition und Ausführung von (komplexen) Anwendungslandschaften (“Compositions”) Unit-/Modultests ...
  31. One more thing …. Private Docker Registries JFrog Artifactory (Docker

    support commercial only) Sonatype Nexus V3.0.0
  32. One more thing …. Docker V1.9 new network stack multi

    host pluggable new storage subsystem pluggable
  33. One more thing …. DockerCon Europe 2015 Docker Nautilus Dockerhub

    upgrade SaaS tool (based on Tutum) Universal Control Plane (on-premise)
  34. Links ... • [Gra01] J. Gray, A Conversation with Werner

    Vogels: Learning form the Amazon technology platform, 2006, siehe: https://queue.acm.org/detail.cfm?id=1142065 • [HuFa01] Jez Humble, David Farley, Continuous Delivery: Reliable Software Releases Through Build, Test and Deployment Automation, 2010, Addison-Wesley • • [Do01] Docker Homepage https://www.docker.com/ • [Do02] Docker Hub https://hub.docker.com/ • [Do03] Docker Engine https://github.com/docker/docker • [Do04] Docker Machine https://github.com/docker/machine • [Do05] Docker Compose https://github.com/docker/compose • [Do06] Docker Toolbox https://github.com/docker/toolbox • • [Http01] Httpie Homepage http://httpie.org/ • • [RHu01] Docker-Maven-Plugin https://github.com/rhuss/docker-maven-plugin • [RHus02] Docker Maven Plugin Shootout: https://github.com/rhuss/shootout-docker-maven • [Spo01] Docker-Maven-Plugin https://github.com/spotify/docker-maven-plugin •