22
Docker for Developers Željko Trogrlić

Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

  • Upload
    others

  • View
    28

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Docker for DevelopersŽeljko Trogrlić

Page 2: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

First Era

• Go through long documentation, if there is one

• Download library source or JARs from Net

• Beg for help

• Be lucky if it works in a week

Page 3: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Second Era

• Use build tools: Maven or Gradle

• Get dependencies from repository

• Do the rest manually or get an VM image• Database

• Web server

• Reverse proxy

• User management (LDAP, Keycloak)

• Documentation, begging, or both

Page 4: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Third Era

• Can new developer become productive within an hour?

Page 5: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Docker Containers vs Virtual Machines

• Shared Kernel• Kernel with all modules is already „on”

• Layered file system

• Shared images

• Bonus: huge selection of ready-made containers

Page 6: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Layered File System

OS

Database

GIS Extensions

Data files

OS

Java

Application server

Application

Page 7: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Layered File System

OS

Database

GIS Extensions

Data files

OS

Java

Application server

Application

Page 8: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Levels of Dockerization

• Docker• static images

• Docker Compose• multi-container environment description

• Docker Swarm or Kubernetes• Managed swarms of containers

Page 9: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

How to Get Docker

• Linux: whatever you usually do

• Windows• Pre-10: Docker Toolbox (uses VirtualBox)

• 10: Docker• Hyper-V

• Linux or Windows containers

Page 10: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Docker & Spring Boot Example

• Application container• OS (Alpine Linux)

• Java

• Spring application

• Database container• OS

• PostgreSQL

• Get it from Docker Hub

Page 11: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Plain Vanilla Configuration

• Bake files into image (docker)• Dockerfile per image

• Orchestrate images (docker-compose)• docker-compose.yml

• Additional compose files

Page 12: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Off We Go!

• gradlew build

• docker-compose build

• docker-compose up –d

• docker-compose ps

• docker-compose logs

• docker-compose down

Page 13: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Development Optimizations

• Expose more ports for debugging

• Update your app quickly

Page 14: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

How to Update Your App

• Rebuild container every time

• Kill container and work as usual• Expose ports from other containers

• Take base image as-is and overlay output file• image: openjdk:8-jre-alpine

• volumes:• - .\server\build\libs:/usr/src/sausage

• - .\server\src\main\resources:/usr/src/sausage/config

Page 15: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Issues: Handling Many Files

• Docker architecture

• Client (CLI)

• Server: build and run

• Docker client copies all files to server• Slooow! Imagine Node.js folder.

• Use docker.ignore*!build/libs!build/resources/main

Page 16: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Issues: Unnamed Volumes Issue

• If files are not present in instance:• Put your files in „Users” directory

• Only that directory is visible from VM

• Otherwise, add directory share to VM

Page 17: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Deploy Faster

• JVM hot swapping

• Spring-Loaded or JRebel

• spring-boot-devtools• Two class loaders

• libraries

• dev output

Page 18: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Production

• Bake files into image

• Expose configuration as environment variables

• Store images into repository

• Devops take it from there

Always do final testing with production scripts!docker-compose

-f docker-compose.yml -f docker-compose.prod.yml up

Page 19: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Third Era

• Run a script or two

• Be productive within an hour

Build tool and Docker recreate complete development environment

Page 20: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Get Example

• https://github.com/zeljkot/presentations/tree/master/docker-intro

Page 21: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Thank you!

Page 22: Docker for Developers - 2019.javacro.hrTrogrloc+-+Docker+for+Developers.… · Docker Containers vs Virtual Machines •Shared Kernel •Kernel with all modules is already „on”

Alpine Linux

• Size: 5 MB (vs 55 for Debian base)

• Base• musl libc (hello 13k vs glibc 662k)

• BusyBox

• ash: Almquist shell from BusyBox

• No Bash and other tools, but could be added