SlideShare a Scribd company logo
Best Practices for Developing &
Deploying Java Applications with
Docker
Eric Smalling - Solution Architect, Docker Inc.
@ericsmalling
JavaOne 2017 | CON7957
2
Who Am I?
● Eric Smalling
○ Solution Architect
Docker Customer Success Team
● ~25 years in software development,
architecture, version control admin, etc…
● ~10 years in build & test automation
● Docker user since pre-1.0 days
● Java developer since 1.1.x days
Agenda
● Docker 101
● Running a simple Java web application in Docker
● Services, stacks & deploying to clusters
● Application management & troubleshooting
● Application Configuration
● Q & A
Docker 101
A quick overview of Docker
Some Docker vocabulary
Docker Image
The basis of a Docker container. Represents a full application
Docker Container
The standard unit in which the application service resides and executes
Docker Engine
Creates, ships and runs Docker containers deployable on a physical or virtual, host
locally, in a datacenter or cloud service provider
Registry Service (Docker Hub or Docker Trusted Registry)
Cloud or server based storage and distribution service for your images
Docker File System
Images, Layers & Containers
● Logical file system by grouping different file system primitives into branches (directories,
file systems, subvolumes, snapshots)
● Each branch represents a layer in a Docker image
● Allows images to be constructed / deconstructed as needed vs. a huge monolithic image
(ala traditional virtual machines)
● When a container is started a writeable layer is added to the “top” of the file system
Docker File System
Containers & Copy on Write
● Super efficient:
Sub second instantiation times for containers
New container can take <1 Mb of space
● Containers appears to be a copy of the original image
But, it is really just a link to the original shared image
● If someone writes a change to the file system, a copy of the affected file/directory is
“copied up”
Docker File System
What about data persistence?
● Volumes allow you to specify a directory in the container that exists outside of the docker
file system structure
● Can be used to share (and persist) data between containers
● Directory persists after the container is deleted
Unless you explicitly delete it
● Can be created in a Dockerfile or via CLI
Dockerfile - Linux + Java Example: Initial state
Image Layers
Kernel
Ubuntu Linux 16:04
Update apt catalogs
Install JDK and curl
Download Tomcat
Install Tomcat
Copy webapp
Start tomcat
Initial State
Building the image
The docker client command
“build” = build an image
“-t” = apply a name and optional build
Image name and optional tag
Path to build context and Dockerfile
Running the image in a container
The docker client command
“run” = start a container
“--rm” = delete container when it exits
“-t” = run with a tty (for console i/o)
“-i” = run in interactive mode
These often are used in combination like this
Image name and optional tag
Demo
Build and run demonstration
Dockerfile - Linux + Java Example: Optimization step 1
Image Layers
Optimization Step 1
Kernel
Ubuntu Linux 16:04
Update apt catalogs, install JDK and curl, clean up
Download Tomcat
Install Tomcat
Copy webapp
Start tomcat
Dockerfile - Linux + Java Example: Optimization step 2
Image Layers
Optimization Step 2
Kernel
OpenJDK:8-alpine
Update apk catalogs, install curl
Download Tomcat
Install Tomcat
Copy webapp
Start tomcat
Dockerfile - Linux + Java Example: Fully Optimized
Image Layers
Fully optimized
Kernel
tomcat:8.5-alpine
Copy webapp
Deploying to Clusters
Services, Stacks and Swarms
More terminology
● Swarm
○ A group of docker hosts, connected and running as a cluster
○ 1-n managers
○ 1-n workers
● Service
○ An application (or part of an application) that provides a specific function
(catalog lookup, web front end, payment processing)
● Stack
○ A way of representing multi-service applications
○ Made up of 1-n services
Stack deploy demo
Simple J2EE application deployment with 2 containers:
● React based front end
● Java based back end
Application Management
Monitoring & Troubleshooting
Health Checks
Helping Docker help you
● HEALTHCHECK instruction in DockerFile
● Tells Docker how to test a container to check that it is still working
● New status added to container lists
● Adds “(healthy)” to Status column in a “docker ps response”
Health Checks
Helping Docker help you
● Examples:
○ HEALTHCHECK CMD curl --fail http://localhost || exit 1
○ HEALTHCHECK --interval=12s --timeout=12s --start-period=30s 
CMD node /healthcheck.js
● References:
○ Documentation: https://docs.docker.com/engine/reference/builder/#healthcheck
○ Elton Stoneman blog about not using curl/iwr: https://t.co/Zgdd1lyzhk
JVM Memory
Tips and tricks
● Always explicitly specify JVM heap size with “-Xmx” arguments
○ By default, J2SE 5.0+ will use up to 25% of the host machine’s RAM or 1GB (whichever is smaller)
○ Container memory limits (enforced via cgroups) are ignored* (*cgroup awareness is planned for Java 9)
○ It’s just a good practice to specify it anyway
● Do use Docker cpu and memory reservations and limits to avoid over-subscribing your host machines
○ --memory
○ --memory-reservation
○ --cpus
○ etc…
● If limiting cpu, be sure to update GC Thread limiter in JVM
○ -XX:ParallelGCThreads
Logging
Dealing with application logs
● Docker EE Reference Architecture document about this: http://dockr.ly/logging
● Do not output logs into the container’s RW layer
○ slow
○ have to exec or cp out of the container to see them
● Option 1: send logs to stdout (see logging drivers below)
○ Visible via “docker logs” command
○ Visible via Docker UCP web console
● Option 2: send logs to volume
○ Many use a centralized NAS/SAN volume for this
● Option 3: Docker logging drivers
Docker Log Drivers
Log drivers available (as of 9/4/17)
Latest always available at: https://docs.docker.com/engine/admin/logging/overview/#supported-logging-drivers
Application Log Drivers
Consider the following when selecting application log drivers:
● syslog and splunk:
○ Good options if log data is highly sensitive since they can be configured to use TLS for
transporting logs.
● journald:
○ great for retaining the usage of docker logs as well as logging Docker daemon logs
○ allows for easier troubleshooting and log portability at the same time
○ logs write first locally, so that there is less reliance on logging infrastructure.
● awslogs or gcplogs:
○ Only if cluster exist solely on a single cloud provider
Application Log Drivers (continued)
Consider the following when selecting application log drivers:
● gelf and fluentd:
○ good choice if there's a NoSQL database somewhere in the environment where the logs can
be stored.
Again, see http://dockr.ly/logging for much more detail on logging.
Troubleshooting
How to use Java tools with container based JVMs
● JVM command line tools via docker exec
○ GC Stats: jstat --gcutil
○ Heap dumps/histograms: jmap
● Expose JMX ports for jconsole or other utilities
● Intelligent health checks
○ More than just “port 8080 is listening”
● Check third party monitoring tools for updated to be “container aware”
○ i.e. Licensing issues with older monitoring tools because each container appears as a new
host
● Also, docker specific commands/tools:
○ docker stats
○ ctop
Application Configuration
Managing multi-environment config’s
Application Configuration
Deploying to disparate environments with identical images
● Build artifacts are your Docker images, not .war files or similar
● Build images in CI, store in registry, deploy same images everywhere
● Patterns and tools to deal with configuration differences
○ Separate Stack yaml files
○ Docker secrets
○ Application configuration via volume mounts
○ Third party configuration tools such as Consul and/or Vault
■ consul-template
■ Joyent Containerpilot
■ Roll-your-own
Environment specific Stacks
● Different environment variable values
● Services that mock production endpoints
○ db
○ web service
prod.yml
dev.yml
Docker Secrets
● Stored encrypted in swam
● Exposed only to nodes that run services that need them
● Presented in container via RAM only tmpfs files
○ never persisted to disk in encrypted format
○ when container stops, secret is no longer present
● All communications between swam nodes via TLS, so secret never in the clear on the wire either
● Different secret values per environment using tags
● UCP can manage who/where secrets are available
Application configuration in volume mounts
● Use volumes that are only available in physical environment they apply to
● Contain environment-specific application configuration properties
● DO NOT store secrets in these (use Docker Secrets or other secure mechanism)
● You can bind mount files (doesn’t have to be full directory structures)
Resources
So much to talk about, so little time to do so!
Resources
So much to talk about, so little time to do so!
● Docker Resources: https://www.docker.com/products/resources
○ Logging Reference Architecture: http://dockr.ly/logging
○ Training: https://training.docker.com
■ Instructor led
■ Self paced with “Play With Docker”
○ Containerizing legacy applications?
■ https://docker.com/MTA
● SquareSpace Blog: Understanding Linux Container Scheduling (with JVMs)
https://engineering.squarespace.com/blog/2017/understanding-linux-container-scheduling
THANK YOU :)
@ericsmalling

More Related Content

What's hot (20)

PDF
Docker 101 Workshop slides (JavaOne 2017)
Eric Smalling
 
PPTX
Integration with Docker and .NET Core
Sriram Hariharan
 
PDF
What's New in Docker 1.12 (June 20, 2016) by Mike Goelzer & Andrea Luzzardi
Mike Goelzer
 
PDF
Docker Security Deep Dive by Ying Li and David Lawrence
Docker, Inc.
 
PDF
Docker on Windows
Stefan Scherer
 
PDF
Troubleshooting Tips from a Docker Support Engineer
Jeff Anderson
 
PDF
Deeper Dive in Docker Overlay Networks
Docker, Inc.
 
PDF
The Golden Ticket: Docker and High Security Microservices by Aaron Grattafiori
Docker, Inc.
 
PPTX
Docker Security Overview
Sreenivas Makam
 
PDF
Introduction to Docker - IndiaOpsUG
Ajeet Singh Raina
 
PPTX
A Survey of Container Security in 2016: A Security Update on Container Platforms
Salman Baset
 
PPTX
Getting started with Docker
Ravindu Fernando
 
PPTX
CI, CD with Docker, Jenkins and Tutum
Sreenivas Makam
 
PDF
How to Improve Your Image Builds Using Advance Docker Build
Docker, Inc.
 
PDF
Docker for Developers - Part 2 by Borja Burgos and Fernando Mayo
Docker, Inc.
 
PPT
Docker introduction
Phuc Nguyen
 
PPTX
Windows Server and Docker - The Internals Behind Bringing Docker and Containe...
Docker, Inc.
 
PDF
Docker for Developers - Part 1 by David Gageot
Docker, Inc.
 
PDF
Docker for Ops - Scott Coulton, Puppet
Docker, Inc.
 
PPTX
Docker Security workshop slides
Docker, Inc.
 
Docker 101 Workshop slides (JavaOne 2017)
Eric Smalling
 
Integration with Docker and .NET Core
Sriram Hariharan
 
What's New in Docker 1.12 (June 20, 2016) by Mike Goelzer & Andrea Luzzardi
Mike Goelzer
 
Docker Security Deep Dive by Ying Li and David Lawrence
Docker, Inc.
 
Docker on Windows
Stefan Scherer
 
Troubleshooting Tips from a Docker Support Engineer
Jeff Anderson
 
Deeper Dive in Docker Overlay Networks
Docker, Inc.
 
The Golden Ticket: Docker and High Security Microservices by Aaron Grattafiori
Docker, Inc.
 
Docker Security Overview
Sreenivas Makam
 
Introduction to Docker - IndiaOpsUG
Ajeet Singh Raina
 
A Survey of Container Security in 2016: A Security Update on Container Platforms
Salman Baset
 
Getting started with Docker
Ravindu Fernando
 
CI, CD with Docker, Jenkins and Tutum
Sreenivas Makam
 
How to Improve Your Image Builds Using Advance Docker Build
Docker, Inc.
 
Docker for Developers - Part 2 by Borja Burgos and Fernando Mayo
Docker, Inc.
 
Docker introduction
Phuc Nguyen
 
Windows Server and Docker - The Internals Behind Bringing Docker and Containe...
Docker, Inc.
 
Docker for Developers - Part 1 by David Gageot
Docker, Inc.
 
Docker for Ops - Scott Coulton, Puppet
Docker, Inc.
 
Docker Security workshop slides
Docker, Inc.
 

Similar to Best Practices for Developing & Deploying Java Applications with Docker (20)

PDF
Introduction to Docker and Monitoring with InfluxData
InfluxData
 
PDF
Docker Up and Running for Web Developers
Amr Fawzy
 
PDF
Docker up and Running For Web Developers
BADR
 
PDF
Docker primer and tips
Samuel Chow
 
PDF
Introduction of Docker and Docker Compose
Dr. Ketan Parmar
 
PDF
Testing Docker Images Security
Jose Manuel Ortega Candel
 
PDF
JOSA TechTalks - Docker in Production
Jordan Open Source Association
 
PDF
Testing Docker Security Linuxlab 2017
Jose Manuel Ortega Candel
 
PDF
[@NaukriEngineering] Docker 101
Naukri.com
 
PPTX
Containerization using docker and its applications
Puneet Kumar Bhatia (MBA, ITIL V3 Certified)
 
PPTX
Containerization using docker and its applications
Puneet Kumar Bhatia (MBA, ITIL V3 Certified)
 
PDF
Testing Docker Images Security -All day dev ops 2017
Jose Manuel Ortega Candel
 
PPTX
Accelerate your development with Docker
Andrey Hristov
 
PDF
Accelerate your software development with Docker
Andrey Hristov
 
PPTX
Getting Started With Docker: Simplifying DevOps
demoNguyen
 
PDF
DCSF 19 Building Your Development Pipeline
Docker, Inc.
 
PDF
Magento Docker Setup.pdf
Abid Malik
 
PDF
Monitoring docker: from zero to Azure
Alessandro Melchiori
 
PPTX
Docker 101 : Introduction to Docker and Containers
Yajushi Srivastava
 
PPTX
Powercoders · Docker · Fall 2021.pptx
IgnacioTamayo2
 
Introduction to Docker and Monitoring with InfluxData
InfluxData
 
Docker Up and Running for Web Developers
Amr Fawzy
 
Docker up and Running For Web Developers
BADR
 
Docker primer and tips
Samuel Chow
 
Introduction of Docker and Docker Compose
Dr. Ketan Parmar
 
Testing Docker Images Security
Jose Manuel Ortega Candel
 
JOSA TechTalks - Docker in Production
Jordan Open Source Association
 
Testing Docker Security Linuxlab 2017
Jose Manuel Ortega Candel
 
[@NaukriEngineering] Docker 101
Naukri.com
 
Containerization using docker and its applications
Puneet Kumar Bhatia (MBA, ITIL V3 Certified)
 
Containerization using docker and its applications
Puneet Kumar Bhatia (MBA, ITIL V3 Certified)
 
Testing Docker Images Security -All day dev ops 2017
Jose Manuel Ortega Candel
 
Accelerate your development with Docker
Andrey Hristov
 
Accelerate your software development with Docker
Andrey Hristov
 
Getting Started With Docker: Simplifying DevOps
demoNguyen
 
DCSF 19 Building Your Development Pipeline
Docker, Inc.
 
Magento Docker Setup.pdf
Abid Malik
 
Monitoring docker: from zero to Azure
Alessandro Melchiori
 
Docker 101 : Introduction to Docker and Containers
Yajushi Srivastava
 
Powercoders · Docker · Fall 2021.pptx
IgnacioTamayo2
 
Ad

More from Eric Smalling (17)

PDF
DockerCon 2023 - Live Demo_Hardening Against Kubernetes Hacks.pdf
Eric Smalling
 
PDF
KubeHuddle NA 2023 - Why should devs care about container security - Eric Sma...
Eric Smalling
 
PDF
ATO 2022 - Why should devs care about container security.pdf
Eric Smalling
 
PDF
KubeCon NA 2022 - Hardening against Kubernetes Hacks.pdf
Eric Smalling
 
PDF
DevOpsDays Chicago 2022 - Hands-on hacking containers and ways to prevent it
Eric Smalling
 
PDF
Look Ma' - Building Java and Go based container images without Dockerfiles
Eric Smalling
 
PDF
Container Stranger Danger - Why should devs care about container security
Eric Smalling
 
PDF
SCaLE 19x - Eric Smalling - Hardening against Kubernetes Hacks
Eric Smalling
 
PDF
DockerCon 2022 - From legacy to Kubernetes, securely & quickly
Eric Smalling
 
PDF
Python Web Conference 2022 - Why should devs care about container security.pdf
Eric Smalling
 
PDF
Why should developers care about container security?
Eric Smalling
 
PDF
AWS live hack: Docker + Snyk Container on AWS
Eric Smalling
 
PDF
AWS live hack: Atlassian + Snyk OSS on AWS
Eric Smalling
 
PDF
Hacking into your containers, and how to stop it!
Eric Smalling
 
PDF
DevSecCon Lightning 2021- Container defaults are a hackers best friend
Eric Smalling
 
PDF
LFX Nov 16, 2021 - Find vulnerabilities before security knocks on your door
Eric Smalling
 
PDF
So. many. vulnerabilities. Why are containers such a mess and what to do abou...
Eric Smalling
 
DockerCon 2023 - Live Demo_Hardening Against Kubernetes Hacks.pdf
Eric Smalling
 
KubeHuddle NA 2023 - Why should devs care about container security - Eric Sma...
Eric Smalling
 
ATO 2022 - Why should devs care about container security.pdf
Eric Smalling
 
KubeCon NA 2022 - Hardening against Kubernetes Hacks.pdf
Eric Smalling
 
DevOpsDays Chicago 2022 - Hands-on hacking containers and ways to prevent it
Eric Smalling
 
Look Ma' - Building Java and Go based container images without Dockerfiles
Eric Smalling
 
Container Stranger Danger - Why should devs care about container security
Eric Smalling
 
SCaLE 19x - Eric Smalling - Hardening against Kubernetes Hacks
Eric Smalling
 
DockerCon 2022 - From legacy to Kubernetes, securely & quickly
Eric Smalling
 
Python Web Conference 2022 - Why should devs care about container security.pdf
Eric Smalling
 
Why should developers care about container security?
Eric Smalling
 
AWS live hack: Docker + Snyk Container on AWS
Eric Smalling
 
AWS live hack: Atlassian + Snyk OSS on AWS
Eric Smalling
 
Hacking into your containers, and how to stop it!
Eric Smalling
 
DevSecCon Lightning 2021- Container defaults are a hackers best friend
Eric Smalling
 
LFX Nov 16, 2021 - Find vulnerabilities before security knocks on your door
Eric Smalling
 
So. many. vulnerabilities. Why are containers such a mess and what to do abou...
Eric Smalling
 
Ad

Recently uploaded (20)

DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 

Best Practices for Developing & Deploying Java Applications with Docker

  • 1. Best Practices for Developing & Deploying Java Applications with Docker Eric Smalling - Solution Architect, Docker Inc. @ericsmalling JavaOne 2017 | CON7957
  • 2. 2 Who Am I? ● Eric Smalling ○ Solution Architect Docker Customer Success Team ● ~25 years in software development, architecture, version control admin, etc… ● ~10 years in build & test automation ● Docker user since pre-1.0 days ● Java developer since 1.1.x days
  • 3. Agenda ● Docker 101 ● Running a simple Java web application in Docker ● Services, stacks & deploying to clusters ● Application management & troubleshooting ● Application Configuration ● Q & A
  • 4. Docker 101 A quick overview of Docker
  • 5. Some Docker vocabulary Docker Image The basis of a Docker container. Represents a full application Docker Container The standard unit in which the application service resides and executes Docker Engine Creates, ships and runs Docker containers deployable on a physical or virtual, host locally, in a datacenter or cloud service provider Registry Service (Docker Hub or Docker Trusted Registry) Cloud or server based storage and distribution service for your images
  • 6. Docker File System Images, Layers & Containers ● Logical file system by grouping different file system primitives into branches (directories, file systems, subvolumes, snapshots) ● Each branch represents a layer in a Docker image ● Allows images to be constructed / deconstructed as needed vs. a huge monolithic image (ala traditional virtual machines) ● When a container is started a writeable layer is added to the “top” of the file system
  • 7. Docker File System Containers & Copy on Write ● Super efficient: Sub second instantiation times for containers New container can take <1 Mb of space ● Containers appears to be a copy of the original image But, it is really just a link to the original shared image ● If someone writes a change to the file system, a copy of the affected file/directory is “copied up”
  • 8. Docker File System What about data persistence? ● Volumes allow you to specify a directory in the container that exists outside of the docker file system structure ● Can be used to share (and persist) data between containers ● Directory persists after the container is deleted Unless you explicitly delete it ● Can be created in a Dockerfile or via CLI
  • 9. Dockerfile - Linux + Java Example: Initial state
  • 10. Image Layers Kernel Ubuntu Linux 16:04 Update apt catalogs Install JDK and curl Download Tomcat Install Tomcat Copy webapp Start tomcat Initial State
  • 11. Building the image The docker client command “build” = build an image “-t” = apply a name and optional build Image name and optional tag Path to build context and Dockerfile
  • 12. Running the image in a container The docker client command “run” = start a container “--rm” = delete container when it exits “-t” = run with a tty (for console i/o) “-i” = run in interactive mode These often are used in combination like this Image name and optional tag
  • 13. Demo Build and run demonstration
  • 14. Dockerfile - Linux + Java Example: Optimization step 1
  • 15. Image Layers Optimization Step 1 Kernel Ubuntu Linux 16:04 Update apt catalogs, install JDK and curl, clean up Download Tomcat Install Tomcat Copy webapp Start tomcat
  • 16. Dockerfile - Linux + Java Example: Optimization step 2
  • 17. Image Layers Optimization Step 2 Kernel OpenJDK:8-alpine Update apk catalogs, install curl Download Tomcat Install Tomcat Copy webapp Start tomcat
  • 18. Dockerfile - Linux + Java Example: Fully Optimized
  • 20. Deploying to Clusters Services, Stacks and Swarms
  • 21. More terminology ● Swarm ○ A group of docker hosts, connected and running as a cluster ○ 1-n managers ○ 1-n workers ● Service ○ An application (or part of an application) that provides a specific function (catalog lookup, web front end, payment processing) ● Stack ○ A way of representing multi-service applications ○ Made up of 1-n services
  • 22. Stack deploy demo Simple J2EE application deployment with 2 containers: ● React based front end ● Java based back end
  • 24. Health Checks Helping Docker help you ● HEALTHCHECK instruction in DockerFile ● Tells Docker how to test a container to check that it is still working ● New status added to container lists ● Adds “(healthy)” to Status column in a “docker ps response”
  • 25. Health Checks Helping Docker help you ● Examples: ○ HEALTHCHECK CMD curl --fail http://localhost || exit 1 ○ HEALTHCHECK --interval=12s --timeout=12s --start-period=30s CMD node /healthcheck.js ● References: ○ Documentation: https://docs.docker.com/engine/reference/builder/#healthcheck ○ Elton Stoneman blog about not using curl/iwr: https://t.co/Zgdd1lyzhk
  • 26. JVM Memory Tips and tricks ● Always explicitly specify JVM heap size with “-Xmx” arguments ○ By default, J2SE 5.0+ will use up to 25% of the host machine’s RAM or 1GB (whichever is smaller) ○ Container memory limits (enforced via cgroups) are ignored* (*cgroup awareness is planned for Java 9) ○ It’s just a good practice to specify it anyway ● Do use Docker cpu and memory reservations and limits to avoid over-subscribing your host machines ○ --memory ○ --memory-reservation ○ --cpus ○ etc… ● If limiting cpu, be sure to update GC Thread limiter in JVM ○ -XX:ParallelGCThreads
  • 27. Logging Dealing with application logs ● Docker EE Reference Architecture document about this: http://dockr.ly/logging ● Do not output logs into the container’s RW layer ○ slow ○ have to exec or cp out of the container to see them ● Option 1: send logs to stdout (see logging drivers below) ○ Visible via “docker logs” command ○ Visible via Docker UCP web console ● Option 2: send logs to volume ○ Many use a centralized NAS/SAN volume for this ● Option 3: Docker logging drivers
  • 28. Docker Log Drivers Log drivers available (as of 9/4/17) Latest always available at: https://docs.docker.com/engine/admin/logging/overview/#supported-logging-drivers
  • 29. Application Log Drivers Consider the following when selecting application log drivers: ● syslog and splunk: ○ Good options if log data is highly sensitive since they can be configured to use TLS for transporting logs. ● journald: ○ great for retaining the usage of docker logs as well as logging Docker daemon logs ○ allows for easier troubleshooting and log portability at the same time ○ logs write first locally, so that there is less reliance on logging infrastructure. ● awslogs or gcplogs: ○ Only if cluster exist solely on a single cloud provider
  • 30. Application Log Drivers (continued) Consider the following when selecting application log drivers: ● gelf and fluentd: ○ good choice if there's a NoSQL database somewhere in the environment where the logs can be stored. Again, see http://dockr.ly/logging for much more detail on logging.
  • 31. Troubleshooting How to use Java tools with container based JVMs ● JVM command line tools via docker exec ○ GC Stats: jstat --gcutil ○ Heap dumps/histograms: jmap ● Expose JMX ports for jconsole or other utilities ● Intelligent health checks ○ More than just “port 8080 is listening” ● Check third party monitoring tools for updated to be “container aware” ○ i.e. Licensing issues with older monitoring tools because each container appears as a new host ● Also, docker specific commands/tools: ○ docker stats ○ ctop
  • 33. Application Configuration Deploying to disparate environments with identical images ● Build artifacts are your Docker images, not .war files or similar ● Build images in CI, store in registry, deploy same images everywhere ● Patterns and tools to deal with configuration differences ○ Separate Stack yaml files ○ Docker secrets ○ Application configuration via volume mounts ○ Third party configuration tools such as Consul and/or Vault ■ consul-template ■ Joyent Containerpilot ■ Roll-your-own
  • 34. Environment specific Stacks ● Different environment variable values ● Services that mock production endpoints ○ db ○ web service prod.yml dev.yml
  • 35. Docker Secrets ● Stored encrypted in swam ● Exposed only to nodes that run services that need them ● Presented in container via RAM only tmpfs files ○ never persisted to disk in encrypted format ○ when container stops, secret is no longer present ● All communications between swam nodes via TLS, so secret never in the clear on the wire either ● Different secret values per environment using tags ● UCP can manage who/where secrets are available
  • 36. Application configuration in volume mounts ● Use volumes that are only available in physical environment they apply to ● Contain environment-specific application configuration properties ● DO NOT store secrets in these (use Docker Secrets or other secure mechanism) ● You can bind mount files (doesn’t have to be full directory structures)
  • 37. Resources So much to talk about, so little time to do so!
  • 38. Resources So much to talk about, so little time to do so! ● Docker Resources: https://www.docker.com/products/resources ○ Logging Reference Architecture: http://dockr.ly/logging ○ Training: https://training.docker.com ■ Instructor led ■ Self paced with “Play With Docker” ○ Containerizing legacy applications? ■ https://docker.com/MTA ● SquareSpace Blog: Understanding Linux Container Scheduling (with JVMs) https://engineering.squarespace.com/blog/2017/understanding-linux-container-scheduling