Improve your Java development env with
DOCKER
Compose & Machine
Copyright 2015 eXo Platform
About Us
Copyright 2015 eXo Platform
● Maxime Gréau
○ @mgreau
● Software Engineer at eXo
● Thomas Delhoménie
○ @tdelhomeni...
Agenda
Copyright 2015 eXo Platform
1. Docker Toolbox
2. Work on multiple technical stacks
3. Uses cases “In A Container”
3...
What’s the
PROBLEM
with my development environment?
Copyright 2015 eXo Platform
Problem 1: Dev environment setup time
Copyright 2015 eXo Platform
Welcome, it’s your first day, you just have to:
● Instal...
The BIG installation doc !
Copyright 2015 eXo Platform
And after 1 hour....
Problem 2: Works on my machine
Copyright 2015 eXo Platform
Problem 3: the matrix hell
Copyright 2015 eXo Platform
MySQL 5.1 MySQL 5.5 Mongo 3.0 Java 7 Java 8
My first app v1 X X
My ...
Fix all those problems with 3 commands!
Copyright 2015 eXo Platform
Pre-requisites
docker, machine & compose installed
The...
Docker
TOOLBOX
For OSX and Windows
Copyright 2015 eXo Platform
Docker Toolbox includes...
Copyright 2015 eXo Platform
● Docker Machine for running the docker-machine binary
● Docker Eng...
Create dev environment
Copyright 2015 eXo Platform
Mac & Windows
> docker-machine create my-machine-name
> eval $(docker-m...
TOURNAMENTS
TENNIS APP
Sample Application
Copyright 2015 eXo Platform
Tennis App - Screenshots
Copyright 2015 eXo Platform
batch-tennis-app.warws-tennis-app.war
WildFly 8.2
WildFly 8.2
JSON-P
1.0
CDI
1.1
WebSocket
API 1.0
JPA
2.1
Batch API
1.0
Tennis App - Architecture - Java EE 7
C...
As a Developer you want to
Work on multiple
technical stacks
Copyright 2015 eXo Platform
WildFly 8.2
Multiple apps with docker compose
Copyright 2015 eXo Platform
MySQL 5.7
Maria DB
10.0
batch-tennis-app.war
Apa...
DEMO 1
Copyright 2015 eXo Platform
Application 1
> git clone URL1 & cd app1
> mvn package
> docker-compose up
open your br...
Tennis App Batch - Dockerfile
Copyright 2015 eXo Platform
FROM jboss/wildfly:8.2.1.Final
RUN mkdir -p /opt/jboss/wildfly/s...
Tennis App Batch - docker-compose.yml
Copyright 2015 eXo Platform
batch_run:
build: ./docker/dev/run/backend
ports:
- "777...
PHP Application - Dockerfile (Wordpress)
Copyright 2015 eXo Platform
FROM php:5.6-apache
RUN a2enmod rewrite
# install the...
PHP Application - docker-compose.yml
Copyright 2015 eXo Platform
wordpress:
image: wordpress
links:
- db:mysql
ports:
- 80...
Others use cases
Copyright 2015 eXo Platform
eXo use case : multi databases support (matrix compatibility pb)
PostgreSQL
9...
Others use cases
Copyright 2015 eXo Platform
Migration between 2 versions of the database
my-app
MySQL
5.5
my-app
MySQL
5.7
Copyright 2015 eXo Platform
USE CASES
“In a Container”
As a Developer you want to
Debug Java app in a
container
Copyright 2015 eXo Platform
How to debug in a container ?
Copyright 2015 eXo Platform
WildFly 8.2
MySQL 5.7
batch-tennis-app.war
Remote debug
DEMO 2
Copyright 2015 eXo Platform
As a Developer you want to
Code and deploy
Copyright 2015 eXo Platform
How to deploy a new war ?
Copyright 2015 eXo Platform
● Update your code in your favorite IDE
● Build with maven
● Open yo...
DEMO 3
Copyright 2015 eXo Platform
As a Developer you want to
Use your IDE to deploy
in a container
Copyright 2015 eXo Platform
IDE starts to support Docker container technology
Copyright 2015 eXo Platform
● Eclipse Mars (2015)
● Netbeans
● IntelliJ ...
As a Developer you want to
Build & Run with
Maven Docker plugins
Copyright 2015 eXo Platform
Docker Maven plugins
Copyright 2015 eXo Platform
mvn tomcat:run
https://github.com/rhuss/docker-maven-plugin
mvn docker:st...
As a Developer you want to
Execute Integration
Tests in containers
Copyright 2015 eXo Platform
Arquillian - Intro
Copyright 2015 eXo Platform
● Automated tests without mocks
● Compatible JUnit/TestNG
● Application Ser...
Arquillian Cube
Copyright 2015 eXo Platform
http://arquillian.org/modules/cube-extension/
Shameless auto-promotion :
http:...
As a Developer you want to
Easily reproduce
production bugs
Copyright 2015 eXo Platform
Test with the production version of the “old” stack
Copyright 2015 eXo Platform
my-app
MySQL 5.5
my-app
MySQL 5.7
> git ch...
As a Developer you want to
Work with an architecture
close to production
Copyright 2015 eXo Platform
Angular / Java EE 7 Application
Copyright 2015 eXo Platform
Apache
HTTPD
UI
Angular
Load
Balancer
WildFly 8.2
WildFly 8.2
...
DEMO 4
Copyright 2015 eXo Platform
DO ALL THE THINGS
WITH DOCKER
Copyright 2015 eXo Platform
Build your projects with docker
Copyright 2015 eXo Platform
You will only need docker tools
on your laptop!
DEMO 5
Copyright 2015 eXo Platform
Docker
TOOLS
Copyright 2015 eXo Platform
GUI for Docker
Copyright 2015 eXo Platform
● Kitematic
● DockerUI
Docker
BEST PRACTICES
Copyright 2015 eXo Platform
Some best practices for development
Copyright 2015 eXo Platform
● Use Docker Machine to organize your images and limit res...
Copyright 2015 eXo Platform
Docker doesn’t invent
the container technology,
BUT
make it possible to use it
easily on your ...
Improve your Java development env with
Docker Compose & Machine
Thanks
@tdelhomenie @mgreau
Code: http://github.com/mgreau...
Prochain SlideShare
Chargement dans…5
×

Improve your Java Environment with Docker

3 750 vues

Publié le

Presentation at the Hanoi JUG about how to improve your Java Environment with Docker

Publié dans : Logiciels, Technologie
0 commentaire
42 j’aime
Statistiques
Remarques
  • Soyez le premier à commenter

Aucun téléchargement
Vues
Nombre de vues
3 750
Sur SlideShare
0
Issues des intégrations
0
Intégrations
531
Actions
Partages
0
Téléchargements
94
Commentaires
0
J’aime
42
Intégrations 0
Aucune incorporation

Aucune remarque pour cette diapositive

Improve your Java Environment with Docker

  1. 1. Improve your Java development env with DOCKER Compose & Machine Copyright 2015 eXo Platform
  2. 2. About Us Copyright 2015 eXo Platform ● Maxime Gréau ○ @mgreau ● Software Engineer at eXo ● Thomas Delhoménie ○ @tdelhomenie ● Software Engineer at eXo
  3. 3. Agenda Copyright 2015 eXo Platform 1. Docker Toolbox 2. Work on multiple technical stacks 3. Uses cases “In A Container” 3.1. Debug 3.2. Code & Deploy 3.3. Deploy from your IDE 3.4. Build & Run with Maven Docker Plugins 3.5. Integration Tests 4. Reproduce production bugs easily 5. Work with an architecture closest to production 6. Do all the things with Docker & co
  4. 4. What’s the PROBLEM with my development environment? Copyright 2015 eXo Platform
  5. 5. Problem 1: Dev environment setup time Copyright 2015 eXo Platform Welcome, it’s your first day, you just have to: ● Install Maven 3.2.3 ● Install JDK 1.7.0_80 ● Install Tomcat 7.0.63 ● Install MySQL 5.5, PostgreSQL 9.1 ● Read the installation doc…
  6. 6. The BIG installation doc ! Copyright 2015 eXo Platform
  7. 7. And after 1 hour....
  8. 8. Problem 2: Works on my machine Copyright 2015 eXo Platform
  9. 9. Problem 3: the matrix hell Copyright 2015 eXo Platform MySQL 5.1 MySQL 5.5 Mongo 3.0 Java 7 Java 8 My first app v1 X X My first app v2 X X X X My other app v1 X X ...
  10. 10. Fix all those problems with 3 commands! Copyright 2015 eXo Platform Pre-requisites docker, machine & compose installed Then 1. Run git clone https://github.com/my-repo/my.git & cd my-project 2. Run docker-compose up 3. Open your browser
  11. 11. Docker TOOLBOX For OSX and Windows Copyright 2015 eXo Platform
  12. 12. Docker Toolbox includes... Copyright 2015 eXo Platform ● Docker Machine for running the docker-machine binary ● Docker Engine for running the docker binary ● Docker Compose for running the docker-compose binary ● Kitematic, the Docker GUI ● Oracle VM VirtualBox Only for OSX and Windows
  13. 13. Create dev environment Copyright 2015 eXo Platform Mac & Windows > docker-machine create my-machine-name > eval $(docker-machine env my-machine-name) Linux Nothing special to do!
  14. 14. TOURNAMENTS TENNIS APP Sample Application Copyright 2015 eXo Platform
  15. 15. Tennis App - Screenshots Copyright 2015 eXo Platform batch-tennis-app.warws-tennis-app.war
  16. 16. WildFly 8.2 WildFly 8.2 JSON-P 1.0 CDI 1.1 WebSocket API 1.0 JPA 2.1 Batch API 1.0 Tennis App - Architecture - Java EE 7 Copyright 2015 eXo Platform batch-tennis-app.war MySQL ws-tennis-app.war Browser CSV
  17. 17. As a Developer you want to Work on multiple technical stacks Copyright 2015 eXo Platform
  18. 18. WildFly 8.2 Multiple apps with docker compose Copyright 2015 eXo Platform MySQL 5.7 Maria DB 10.0 batch-tennis-app.war Apache Wordpress
  19. 19. DEMO 1 Copyright 2015 eXo Platform Application 1 > git clone URL1 & cd app1 > mvn package > docker-compose up open your browser ! Application 2 > git clone URL2 & cd app2 > docker-compose up open your browser !
  20. 20. Tennis App Batch - Dockerfile Copyright 2015 eXo Platform FROM jboss/wildfly:8.2.1.Final RUN mkdir -p /opt/jboss/wildfly/standalone/deployments/ROOT.war/ RUN touch /opt/jboss/wildfly/standalone/deployments/ROOT.war.dodeploy VOLUME ["/opt/jboss/wildfly/standalone/deployments/ROOT.war/"] ENV MYSQL_CONNECTOR_VERSION 5.1.34 RUN /opt/jboss/wildfly/bin/add-user.sh -up mgmt-users.properties admin Admin#70365 --silent # Install mysql driver RUN curl -L -o /opt/jboss/wildfly/standalone/deployments/mysql-connector-java.jar https://repo1. maven.org/maven2/mysql/mysql-connector-java/${MYSQL_CONNECTOR_VERSION}/mysql- connector-java-${MYSQL_CONNECTOR_VERSION}.jar CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]
  21. 21. Tennis App Batch - docker-compose.yml Copyright 2015 eXo Platform batch_run: build: ./docker/dev/run/backend ports: - "7777:8080" volumes: - ./app/batch/target/batch:/opt/jboss/wildfly/standalone/deployments/ROOT.war/ links: - db dbdata: image: mysql:5.7 volumes: - /var/lib/mysql db: image: mysql:5.7 volumes_from: - dbdata environment: - MYSQL_ROOT_PASSWORD=tennistour - MYSQL_DATABASE=tennistour - MYSQL_USER=tennistour - MYSQL_PASSWORD=tennistour
  22. 22. PHP Application - Dockerfile (Wordpress) Copyright 2015 eXo Platform FROM php:5.6-apache RUN a2enmod rewrite # install the PHP extensions we need RUN apt-get update && apt-get install -y libpng12-dev libjpeg-dev && rm -rf /var/lib/apt/lists/* && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr && docker-php-ext-install gd RUN docker-php-ext-install mysqli VOLUME /var/www/html ENV WORDPRESS_VERSION 4.3.1 ENV WORDPRESS_SHA1 b2e5652a6d2333cabe7b37459362a3e5b8b66221 # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress RUN curl -o wordpress.tar.gz -SL https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz && echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - && tar -xzf wordpress.tar.gz -C /usr/src/ && rm wordpress.tar.gz && chown -R www-data:www-data /usr/src/wordpress COPY docker-entrypoint.sh /entrypoint.sh # grr, ENTRYPOINT resets CMD now ENTRYPOINT ["/entrypoint.sh"] CMD ["apache2-foreground"]
  23. 23. PHP Application - docker-compose.yml Copyright 2015 eXo Platform wordpress: image: wordpress links: - db:mysql ports: - 8080:80 db: image: mariadb environment: MYSQL_ROOT_PASSWORD: example
  24. 24. Others use cases Copyright 2015 eXo Platform eXo use case : multi databases support (matrix compatibility pb) PostgreSQL 9.3 MySQL 5.6MySQL 5.5 PostgreSQL 9.4 Oracle 11gR2
  25. 25. Others use cases Copyright 2015 eXo Platform Migration between 2 versions of the database my-app MySQL 5.5 my-app MySQL 5.7
  26. 26. Copyright 2015 eXo Platform USE CASES “In a Container”
  27. 27. As a Developer you want to Debug Java app in a container Copyright 2015 eXo Platform
  28. 28. How to debug in a container ? Copyright 2015 eXo Platform WildFly 8.2 MySQL 5.7 batch-tennis-app.war Remote debug
  29. 29. DEMO 2 Copyright 2015 eXo Platform
  30. 30. As a Developer you want to Code and deploy Copyright 2015 eXo Platform
  31. 31. How to deploy a new war ? Copyright 2015 eXo Platform ● Update your code in your favorite IDE ● Build with maven ● Open your browser !
  32. 32. DEMO 3 Copyright 2015 eXo Platform
  33. 33. As a Developer you want to Use your IDE to deploy in a container Copyright 2015 eXo Platform
  34. 34. IDE starts to support Docker container technology Copyright 2015 eXo Platform ● Eclipse Mars (2015) ● Netbeans ● IntelliJ IDEA v14.1
  35. 35. As a Developer you want to Build & Run with Maven Docker plugins Copyright 2015 eXo Platform
  36. 36. Docker Maven plugins Copyright 2015 eXo Platform mvn tomcat:run https://github.com/rhuss/docker-maven-plugin mvn docker:start
  37. 37. As a Developer you want to Execute Integration Tests in containers Copyright 2015 eXo Platform
  38. 38. Arquillian - Intro Copyright 2015 eXo Platform ● Automated tests without mocks ● Compatible JUnit/TestNG ● Application Server agnostic ● Embedded/Managed/Client modes
  39. 39. Arquillian Cube Copyright 2015 eXo Platform http://arquillian.org/modules/cube-extension/ Shameless auto-promotion : http://mgreau.com/posts/2015/03/03/docker- asciidoctorj-wildfly-arquillian.html
  40. 40. As a Developer you want to Easily reproduce production bugs Copyright 2015 eXo Platform
  41. 41. Test with the production version of the “old” stack Copyright 2015 eXo Platform my-app MySQL 5.5 my-app MySQL 5.7 > git checkout v1 > “build” > docker-compose up New dev stackProd stack 5.5 5.7 v1 v2
  42. 42. As a Developer you want to Work with an architecture close to production Copyright 2015 eXo Platform
  43. 43. Angular / Java EE 7 Application Copyright 2015 eXo Platform Apache HTTPD UI Angular Load Balancer WildFly 8.2 WildFly 8.2 batch-tennis-app.war MySQL ws-tennis-app.war Cache Redis CSV WildFly 8.2 ws-tennis-app.war WildFly 8.2 ws-tennis-app.war
  44. 44. DEMO 4 Copyright 2015 eXo Platform
  45. 45. DO ALL THE THINGS WITH DOCKER Copyright 2015 eXo Platform
  46. 46. Build your projects with docker Copyright 2015 eXo Platform You will only need docker tools on your laptop!
  47. 47. DEMO 5 Copyright 2015 eXo Platform
  48. 48. Docker TOOLS Copyright 2015 eXo Platform
  49. 49. GUI for Docker Copyright 2015 eXo Platform ● Kitematic ● DockerUI
  50. 50. Docker BEST PRACTICES Copyright 2015 eXo Platform
  51. 51. Some best practices for development Copyright 2015 eXo Platform ● Use Docker Machine to organize your images and limit resources usage (CPU, memory, …) ● Use volume containers to keep your data safe (schema) ● Useful docker commands: ○ stopped docker containers : docker stop $(docker ps -q) ○ remove dangling docker images: ■ docker rmi $(docker images -q -f "dangling=true") ○ and more: https://github.com/javaee-samples/docker- java/blob/master/chapters/docker-commands.adoc
  52. 52. Copyright 2015 eXo Platform Docker doesn’t invent the container technology, BUT make it possible to use it easily on your laptop!
  53. 53. Improve your Java development env with Docker Compose & Machine Thanks @tdelhomenie @mgreau Code: http://github.com/mgreau/docker4dev-tennistour-app

×