docker+java

30
Docker + Java Elek Márton @anzix 2015 March DPC Consulting

Upload: dpc-consulting-ltd

Post on 08-Jan-2017

521 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Docker+java

Docker + Java

Elek Márton@anzix

2015 MarchDPC Consulting

Page 2: Docker+java

Docker+Java

Page 3: Docker+java

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

Page 4: Docker+java

Docker run

Page 5: Docker+java

Docker run

Page 6: Docker+java

Docker run

Page 7: Docker+java

Two main use case Start a predefined container

docker run jenkins

Start a command in a well defined envdocker run ubuntu uname -a

docker run ubuntu bash

Page 8: Docker+java

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

Page 9: Docker+java

● 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

Page 10: Docker+java

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:8ADD build/version /app/versionWORKDIR /appCMD ["bin/start.sh"]

Page 11: Docker+java

● 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

Page 12: Docker+java

Docker ps

Page 13: Docker+java

Upload to a repository● docker push/pull● Very similar to the git concept

– Versions– Tagging

docker imagesdocker tag 8dbd9e392a dpc.hu:5000/backenddocker push dpc.hu:5000/ubuntu

Repository servers:● docker● artifactory

Page 14: Docker+java

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”

Page 15: Docker+java

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.”

Page 16: Docker+java

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

Page 17: Docker+java

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

Page 18: Docker+java

(Without) Docker composedocker 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

Page 19: Docker+java

Docker composemysqldb: image: mysql:latest environment: MYSQL_DATABASE: sample MYSQL_USER: mysql MYSQL_PASSWORD: mysql MYSQL_ROOT_PASSWORD: supersecretmywildfly: image: arungupta/wildfly-mysql-javaee7 links: - mysqldb:db ports: - 8080:8080

Page 20: Docker+java

Use it from Windows/OSX/...● Boot2docker

– Minimal virtual container (Virtualbox)– Tools to run containers in the Virtualbox

● Docker Machine installer– Windows/Linux/OSX

Page 21: Docker+java

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...

Page 22: Docker+java

Docker+Java

Page 23: Docker+java

Example standalone appDockerfileFROM java:8WORKDIR /myappCMD ["bin/myproj"]COPY build/install/myproj /myapp

mvn install/gradle packagedocker build .

//upload to the repository with docker push

docker pull dpc.hu:5000/backenddocker run dpc.hu:5000/backend

Page 24: Docker+java

Example J2EE applicationFROM 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/

Page 25: Docker+java

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

Page 26: Docker+java

Maven/SBT/Gradledocker plugin

Page 27: Docker+java

Artifactory

Page 28: Docker+java

Continuous Deployment

See: Delivery pipline and zero downtime

Page 29: Docker+java

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

Page 30: Docker+java

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