Achieving Continuous Delivery of Java Enterprise applications with Docker Petyo Dimitrov

Agenda • • • • • • • A typical Enterprise Java landscape Continuous Delivery pipeline Identified problems What are Docker containers? Docker “ecosystem” Demo Tips & Tricks 08.10.2016 2

Dev landscape for Java EE applications 08.10.2016 3

Continuous Delivery pipeline 08.10.2016 4

problems 08.10.2016 5

inadequate packaging of application artifacts 08.10.2016 6

inconsistencies across environments 08.10.2016 7

high cost supporting multiple static environments 08.10.2016 8

lack of freedom experimenting with new languages, technologies and frameworks 08.10.2016 9

docker 08.10.2016 10

08.10.2016 11

High level view of a container • it is like a lightweight Virtual Machine • it provides: – own process space – own network interface – running stuff as root 08.10.2016 12

Low level view of a container • • • • • container = “process in a box” shares kernel with host  boots faster processes run directly on the host there is no device emulation none or little CPU, memory, network and I/O overhead 08.10.2016 13

Virtual machines vs Containers 08.10.2016 14

How does it work? - Isolation • isolation via namespaces – pid, mnt, net, uts, user, ipc • isolation via control groups – memory, cpu, blkio, devices 08.10.2016 15

How does it work? - Storage • • • • union file system (aufs, overlayfs) allows reusing common layers reduces traffic and storage allows tracking changes • copy-on-write pattern used for speed 08.10.2016 16

Developers • care about applications • put stuff in containers – code & data – libraries – applications Operations • care about containers • work with containers – logging & monitoring – networking – scaling 08.10.2016 17

docker “ecosystem” 08.10.2016 18

Client-Server model 08.10.2016 19

Docker engine • runs and commoditizes Linux containers • uses copy-on-write for quick provisioning • runs as daemon and has CLI • allows building & sharing images • functionality is exposed via REST API • defines standard format for containers 08.10.2016 20

Docker commands • ~40 commands • work with: – images – containers – registry 08.10.2016 21

Dockerfile-s FROM jenkins:1.625.1 MAINTAINER Petyo Dimitrov ENV REFRESHED_AT 2015-10-24 RUN curl -L https://github.com/… > /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose RUN mkdir /var/cache/jenkins RUN chown -R jenkins:jenkins /var/cache/jenkins docker build –t myjenkins .

Set Defaults ENV JAVA_OPTS=”-Xmx6144m” ENV JENKINS_OPTS=”—handlerCountMax=300 —webroot=/var/cache/jenkins/war” COPY plugins.txt /plugins.txt RUN /usr/local/bin/plugins.sh /plugins.txt 08.10.2016

22

Docker Compose • manages a collection of containers • fast, isolated development environments using Docker • define env via YAML file • quick and easy to start docker-compose up –d 08.10.2016 23

YAML example 08.10.2016 24

Demonstration https://github.com/petyodimitrov/spring-music.git https://github.com/petyodimitrov/app-setup.git https://github.com/petyodimitrov/ci-setup.git 08.10.2016 25

Standard Java application build 08.10.2016 26

Docker containers build 08.10.2016 27

Adding system testing 08.10.2016 28

Combining all the parts 08.10.2016 29

Runtime view of containers 08.10.2016 30

Demonstration 08.10.2016 31

Tips & tricks (1) • Decide on a strategy for introducing Docker in the project • • • • Keep and eye for improvements & changes (e.g. networks) Keep containers simple (i.e. only one/few processes) Automate, automate, automate … (via docker or other CM tools) Use initialization & validation scripts (e.g. init, supervisord) 08.10.2016 32

Tips & tricks (2) • Review Dockerfile-s as part of development process (e.g. peer reviews) 14.04.3 FROM alpine-java ubuntu:latest ENV REPO=10.0.1.1:1236 RUN RUN apt-get apt-get update update –y –y && \ apt-get install curl RUN apt-get install curl –y # unnecessary RUN apt-get install wget -y verify checksum RUN curl -L https ${REPO} http://10.0.1.1:1236/something.jar USER USERROOT nobody CMD java –jar something.jar 08.10.2016 33

petyo.dimitrov @musala.com 08.10.2016 Achieving Continuous Delivery of Java Enterprise applications with Docker 34