Docker + Java
Elek Márton
@anzix
2015 March
DPC Consulting
Docker+Java
What is docker
● Lightweight virtualization
– Container
● Repository of virtual images
– 100 official image
– ~45000 publi...
Docker run
Docker run
Docker run
Two main use case
Start a predefined
container
docker run jenkins
Start a command in a
well defined env
docker run ubuntu
...
Volumes
● Every container is a one time container.
– All of the files will be deleted together with the container
● What a...
● How to access?
– By default docker containers use internal unique IP
– An additional process forwards ports
● Port forwa...
Create a docker container
● Snapshot an existing container
– Easy but non reproducible
– docker commit
● Create step-by-st...
● Usually one process
“In almost all cases, you should only run a single
process in a single container.
Decoupling applica...
Docker ps
Upload to a repository
● docker push/pull
● Very similar to the git concept
– Versions
– Tagging
docker images
docker tag ...
Docker definition
“Docker is an open platform for developers and
sysadmins to build, ship, and run distributed
application...
Docker definition
“… Docker enables apps
to be quickly assembled from components
● and eliminates the friction between
● d...
What is missing
● How to create an alias for a complex command line
– Docker compose (was fig)
– Crane
● How to manage mul...
Docker is ecosystem
● ContainerOS
– CoreOS, Project Atomic, Boot2Docker
● Open source PaaS
– Flynn, Dokuu, Deis
● Schedule...
(Without) Docker compose
docker run --name mysqldb
-e MYSQL_USER=mysql
-e MYSQL_PASSWORD=mysql
-e MYSQL_DATABASE=sample
-e...
Docker compose
mysqldb:
image: mysql:latest
environment:
MYSQL_DATABASE: sample
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
MY...
Use it from Windows/OSX/...
● Boot2docker
– Minimal virtual container (Virtualbox)
– Tools to run containers in the Virtua...
Who uses it?
● All of the big players:
● Amazon Beanstalk
– Dedicated container based hosting
● Google Cloud Platform
– Co...
Docker+Java
Example standalone app
Dockerfile
FROM java:8
WORKDIR /myapp
CMD ["bin/myproj"]
COPY build/install/myproj /myapp
mvn insta...
Example J2EE application
FROM jboss/wildfly
RUN add-user.sh admin Admin#70365 --silent
CMD ["/opt/jboss/wildfly/bin/standa...
Recipes
● Arun Gupta:
9 Docker recipes for Java EE
Applications
– Use Docker Machine
– Link local mysql and wildfly togeth...
Maven/SBT/Gradle
docker plugin
Artifactory
Continuous Deployment
See: Delivery pipline and zero downtime
Arquilian Cube (1.0.0 Alpha4)
“With this extension you can start a Docker container with a server installed,
deploy the re...
Summary
● Container technology is the present
– lightweight virtualization
– packaging
– repository
● Reusable components
...
Upcoming SlideShare
Loading in …5
×

Docker+java

548 views

Published on

Docker introduction and information about the usage in the java world.

Event: Hungarian Oracle User Goup conference, 2015.03

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
548
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Docker+java

  1. 1. Docker + Java Elek Márton @anzix 2015 March DPC Consulting
  2. 2. Docker+Java
  3. 3. What is docker ● Lightweight virtualization – Container ● Repository of virtual images – 100 official image – ~45000 public images ● Versioning support – To upgrade a container ● Only for linux – Just a filesystem, the kernel of the host system is used – Windows out of scope ● Similar to – BSD jails, Linux LXC, Solaris zones
  4. 4. Docker run
  5. 5. Docker run
  6. 6. Docker run
  7. 7. Two main use case Start a predefined container docker run jenkins Start a command in a well defined env docker run ubuntu uname -a docker run ubuntu bash
  8. 8. Volumes ● Every container is a one time container. – All of the files will be deleted together with the container ● What about persisted data? – Solution: volumes docker run -v /root/jenkins:/var/jenkins_home jenkins
  9. 9. ● How to access? – By default docker containers use internal unique IP – An additional process forwards ports ● Port forwards should be defined docker run -v /root/jenkins:/var/jenkins_home -p 4567:8080 jenkins Port forward
  10. 10. Create a docker container ● Snapshot an existing container – Easy but non reproducible – docker commit ● Create step-by-step from an existing container – docker build . FROM java:8 ADD build/version /app/version WORKDIR /app CMD ["bin/start.sh"]
  11. 11. ● Usually one process “In almost all cases, you should only run a single process in a single container. Decoupling applications into multiple containers makes it much easier to scale horizontally and reuse containers. If that service depends on another service, make use of container linking.” Docker best practices What is inside a container
  12. 12. Docker ps
  13. 13. Upload to a repository ● docker push/pull ● Very similar to the git concept – Versions – Tagging docker images docker tag 8dbd9e392a dpc.hu:5000/backend docker push dpc.hu:5000/ubuntu Repository servers: ● docker ● artifactory
  14. 14. Docker definition “Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications. Consisting of Docker Engine, a portable, ● lightweight runtime and ● packaging tool, and ● Docker Hub, a cloud service for sharing applications and automating workflows”
  15. 15. Docker definition “… Docker enables apps to be quickly assembled from components ● and eliminates the friction between ● development, QA, and production environments.” “As a result, IT can ship faster and run the same app, unchanged, on laptops, data center VMs, and any cloud.”
  16. 16. What is missing ● How to create an alias for a complex command line – Docker compose (was fig) – Crane ● How to manage multiple machines all together/schedule containers – Kubernetes, OpenShift ● Hande logical group of containers together – Kubernetes, OpenShift
  17. 17. Docker is ecosystem ● ContainerOS – CoreOS, Project Atomic, Boot2Docker ● Open source PaaS – Flynn, Dokuu, Deis ● Scheduler/Orchestration/Management – Kubernetes, Crane, Docker Compose(fig) ● Continuous Integration – Jennkins plugins, … See also https://www.mindmeister.com/389671722/docker-ecosystem
  18. 18. (Without) Docker compose docker run --name mysqldb -e MYSQL_USER=mysql -e MYSQL_PASSWORD=mysql -e MYSQL_DATABASE=sample -e MYSQL_ROOT_PASSWORD=supersecret -d mysql docker run --name mywildfly --link mysqldb:db -p 8080:8080 -d arungupta/wildfly-mysql-javaee7
  19. 19. Docker compose mysqldb: image: mysql:latest environment: MYSQL_DATABASE: sample MYSQL_USER: mysql MYSQL_PASSWORD: mysql MYSQL_ROOT_PASSWORD: supersecret mywildfly: image: arungupta/wildfly-mysql-javaee7 links: - mysqldb:db ports: - 8080:8080
  20. 20. Use it from Windows/OSX/... ● Boot2docker – Minimal virtual container (Virtualbox) – Tools to run containers in the Virtualbox ● Docker Machine installer – Windows/Linux/OSX
  21. 21. Who uses it? ● All of the big players: ● Amazon Beanstalk – Dedicated container based hosting ● Google Cloud Platform – Containers on Google Cloud Platform powered by kubernetes ● RedHat OpenShift v3 – The new version is based on kubernetes/docker ● HP – Operations Orchestration And others...
  22. 22. Docker+Java
  23. 23. Example standalone app Dockerfile FROM java:8 WORKDIR /myapp CMD ["bin/myproj"] COPY build/install/myproj /myapp mvn install/gradle package docker build . //upload to the repository with docker push docker pull dpc.hu:5000/backend docker run dpc.hu:5000/backend
  24. 24. Example J2EE application FROM jboss/wildfly RUN add-user.sh admin Admin#70365 --silent CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"] COPY target/helloworld.war /opt/jboss/wildfly/standalone/deployments/
  25. 25. Recipes ● Arun Gupta: 9 Docker recipes for Java EE Applications – Use Docker Machine – Link local mysql and wildfly together – Link remote containers – Deploy Java EE Application from Eclipse
  26. 26. Maven/SBT/Gradle docker plugin
  27. 27. Artifactory
  28. 28. Continuous Deployment See: Delivery pipline and zero downtime
  29. 29. Arquilian Cube (1.0.0 Alpha4) “With this extension you can start a Docker container with a server installed, deploy the required deployable file within it and execute Arquillian tests. The key point here is that if Docker is used as deployable platform in production, your tests are executed in a the same container as it will be in production, so your tests are even more real than before. But it also lets you start a container with every required service like database, mail server, … and instead of stubbing or using fake objects your tests can use real servers.” https://github.com/arquillian/arquillian-cube
  30. 30. Summary ● Container technology is the present – lightweight virtualization – packaging – repository ● Reusable components – Continuous delivery – Use exactly the same environment – limit resources – Easy to create test containers ● Growing ecosystem – Supported solutions from the biggest vendors to the smallest startup

×