SlideShare a Scribd company logo
1 of 41
Download to read offline
Ship your Scala code often
and easy with Docker
Marcus Lönnberg
marcus@lonnberg.nu
github.com/marcuslonnberg
@lonnbergm
e-bokföring
Agenda
• Intro to Docker
• Building Docker images with sbt
• Manage Docker containers with Scala
• Docker.at(SpeedLedger)
Platform
Open source
Client - server
REST API
Immutable images
Container virtualization
Traditional VMs Docker
Docker image
Dockerfile
Container
Docker image
Dockerfile
Container
> docker build --tag=myimage
> docker run myimage
Live demo
Building and shipping Docker images
Machine 1
Dockerfile + files
Machine x
> docker pull myimage
> docker run myimage
Registry
> docker build --tag=myimage
> docker push myimage
Machine xMachine x
Building Docker images from sbt
Manually building a Scala application
as a Docker image
1. Produce a fat JAR
2. Define a Dockerfile
3. Build a Docker image
0. Current sbt build
name := "fancy-service"

organization := "demo"



libraryDependencies ++= Seq(

"com.typesafe.akka" %% "akka-actor" % "2.3.9",

"io.spray" %% "spray-routing" % “1.3.3”,
...

)
build.sbt
1. sbt-assembly gives us a fat JAR
project/plugins.sbt
> sbt assembly
…
[info] Packaging out/fancy-service.jar ...
…
[success] Total time: 6 s
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.13.0")
2. Define a Dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get install -y openjdk-8-jre-headless
COPY fancy-service.jar /app/fancy-service.jar
WORKDIR /app
ENTRYPOINT java -jar fancy-service.jar
EXPOSE 8080
Dockerfile
2. Define a Dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get install -y openjdk-8
COPY fancy-service.jar
WORKDIR /app
ENTRYPOINT java -jar fancy-service.jar
EXPOSE 8080
Dockerfile
FROM java:8-jre
WORKDIR /app
EXPOSE 8080
ENTRYPOINT java -jar fancy-service.jar
COPY fancy-service.jar /app/fancy-service.jar
good
3. Building a Docker image
> docker build -t demo/fancy-service .
Sending build context to Docker daemon
Step 0 : FROM java:8-jre
---> 028f36974b77
Step 1 : WORKDIR /app
---> fb8108515091
Step 2 : EXPOSE 8080
---> 9512be4df795
Step 3 : ENTRYPOINT java -jar fancy-service.jar
---> 839dd75f5a96
Step 4 : COPY fancy-service.jar /app/fancy-service.jar
---> 948eb875c3b1
Removing intermediate container f9eeb9406fc7
Successfully built 948eb875c3b1
sbt-docker
sbt-docker
addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.1.0")
project/plugins.sbt
enablePlugins(DockerPlugin)
build.sbt
Dockerfile DSL
def jarFile: File
def jarName: String



new Dockerfile {

from("java:8-jre")

workDir("/app")

expose(8080)

entryPointRaw(s"java -jar $jarName")

copy(jarFile, s"/app/$jarName")

}
Putting it all together
docker <<= docker.dependsOn(assembly)



dockerfile in docker := {

val jarFile = (assemblyOutputPath in assembly).value

val jarName = name.value + ".jar"


new Dockerfile {

from("java:8-jre")

workDir("/app")

expose(8080)

entryPointRaw(s"java -jar $jarName")

copy(jarFile, s"/app/$jarName")

}

}
build.sbt
Let’s build an image
> sbt docker
…
[info] Packaging out/fancy-service.jar ...
…
[info] Step 0 : FROM java:8-jre
[info] ---> 028f36974b77
…
[info] Successfully built 30c376822ced
[info] Tagging image 30c376822ced with name: demo/fancy-service:0.1-SNAPSHOT
[info] Tagging image 30c376822ced with name: demo/fancy-service:latest
[success] Total time: 20 s
Image names
imageNames in docker := Seq(

ImageName("demo/fancy-service:" + version.value),

ImageName("demo/fancy-service:latest")

)
build.sbt
Immutable Dockerfile
def jarFile: File
def jarName: String



Dockerfile.empty

.from("java:8-jre")

.workDir("/app")

.expose(8080)

.entryPointRaw(s"java -jar $jarName")

.copy(jarFile, s"/app/$jarName")
Build options
buildOptions in docker := BuildOptions(

cache = true,

removeIntermediateContainers = BuildOptions.Remove.OnSuccess,

pullBaseImage = BuildOptions.Pull.Always

)
build.sbt
sbt-docker
• Define Dockerfiles with a DSL
• Dynamically name your images
• Push images to a registry
github.com/marcuslonnberg/sbt-docker
Manage Docker containers
from Scala
REST API
REST API
scala-docker
Live coding
Docker.at(SpeedLedger)
Build pipeline
Dev machine
Build server
Test
Production
Registry
git repo
> git push
> sbt dockerBuildAndPush
> docker pull image
Dev machine
Tagging Docker images with git
imageNames in docker := Seq(

ImageName("demo/fancy-service:" + git.gitHeadCommit.value.get),

ImageName("demo/fancy-service:" + git.gitCurrentBranch.value)

)
Labels with build info
val labels = Map(

"build.commitId" -> git.gitHeadCommit.value.get,

"build.branch" -> git.gitCurrentBranch.value,

"build.appName" -> name.value,

"build.buildTime" -> Platform.currentTime.toString

)



new Dockerfile {

…

label(labels)

…

}
Docker >= 1.6
Internal sbt plugin
• Adds common libraries
• Generates build info
• Configures logging
• Adds monitoring
• Sets good runtime properties
• Defines a Dockerfile template
What we have learned
• Order instructions in Dockerfiles for fast builds
• Docker is very easy to use except for networking and 

file persistence
• Define own base images but use official when ones exist
• Building tools around Docker is easy and fun
Links
• github.com/marcuslonnberg/sbt-docker
• github.com/marcuslonnberg/scala-docker
• github.com/sbt/sbt-assembly
• github.com/sbt/sbt-native-packager
Thank you!
marcus@lonnberg.nu
github.com/marcuslonnberg
@lonnbergm

More Related Content

What's hot

Using Kubernetes for Continuous Integration and Continuous Delivery
Using Kubernetes for Continuous Integration and Continuous DeliveryUsing Kubernetes for Continuous Integration and Continuous Delivery
Using Kubernetes for Continuous Integration and Continuous DeliveryCarlos Sanchez
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeDanielle Madeley
 
Installaling Puppet Master and Agent
Installaling Puppet Master and AgentInstallaling Puppet Master and Agent
Installaling Puppet Master and AgentRanjit Avasarala
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Rajmahendra Hegde
 
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2days
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2daysUsing Kubernetes for Continuous Integration and Continuous Delivery. Java2days
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2daysCarlos Sanchez
 
Cloning Running Servers with Docker and CRIU by Ross Boucher
Cloning Running Servers with Docker and CRIU by Ross BoucherCloning Running Servers with Docker and CRIU by Ross Boucher
Cloning Running Servers with Docker and CRIU by Ross BoucherDocker, Inc.
 
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGHDeploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGHErica Windisch
 
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015Stephane Manciot
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)Soshi Nemoto
 
Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013
Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013
Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013Roland Tritsch
 

What's hot (20)

Using Kubernetes for Continuous Integration and Continuous Delivery
Using Kubernetes for Continuous Integration and Continuous DeliveryUsing Kubernetes for Continuous Integration and Continuous Delivery
Using Kubernetes for Continuous Integration and Continuous Delivery
 
Running Django on Docker: a workflow and code
Running Django on Docker: a workflow and codeRunning Django on Docker: a workflow and code
Running Django on Docker: a workflow and code
 
Installaling Puppet Master and Agent
Installaling Puppet Master and AgentInstallaling Puppet Master and Agent
Installaling Puppet Master and Agent
 
SBT Crash Course
SBT Crash CourseSBT Crash Course
SBT Crash Course
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2days
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2daysUsing Kubernetes for Continuous Integration and Continuous Delivery. Java2days
Using Kubernetes for Continuous Integration and Continuous Delivery. Java2days
 
Cloning Running Servers with Docker and CRIU by Ross Boucher
Cloning Running Servers with Docker and CRIU by Ross BoucherCloning Running Servers with Docker and CRIU by Ross Boucher
Cloning Running Servers with Docker and CRIU by Ross Boucher
 
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGHDeploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
 
ABCs of docker
ABCs of dockerABCs of docker
ABCs of docker
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
Packaging et déploiement d'une application avec Docker et Ansible @DevoxxFR 2015
 
Docker Starter Pack
Docker Starter PackDocker Starter Pack
Docker Starter Pack
 
SBT Concepts, part 2
SBT Concepts, part 2SBT Concepts, part 2
SBT Concepts, part 2
 
A Hands-on Introduction to Docker
A Hands-on Introduction to DockerA Hands-on Introduction to Docker
A Hands-on Introduction to Docker
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 
Dockerfile
Dockerfile Dockerfile
Dockerfile
 
Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013
Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013
Sbt Concepts - Tips, Tricks, Sandbox, ... 02/2013
 
Docker Started
Docker StartedDocker Started
Docker Started
 

Viewers also liked

Scala, docker and testing, oh my! mario camou
Scala, docker and testing, oh my! mario camouScala, docker and testing, oh my! mario camou
Scala, docker and testing, oh my! mario camouJ On The Beach
 
Unsucking Error Handling with Futures
Unsucking Error Handling with FuturesUnsucking Error Handling with Futures
Unsucking Error Handling with FuturesGaryCoady
 
Continous delivery - lad koden flyde 2014
Continous delivery - lad koden flyde 2014Continous delivery - lad koden flyde 2014
Continous delivery - lad koden flyde 2014BestBrains
 
Automated Performance Testing With J Meter And Maven
Automated  Performance  Testing With  J Meter And  MavenAutomated  Performance  Testing With  J Meter And  Maven
Automated Performance Testing With J Meter And MavenPerconaPerformance
 
Akka Http , Routes, Streams with Scala
Akka Http , Routes, Streams with ScalaAkka Http , Routes, Streams with Scala
Akka Http , Routes, Streams with ScalaJerry Kuru
 
Using Jenkins and Jmeter to build a scalable Load Testing solution
Using Jenkins and Jmeter to build a scalable Load Testing solutionUsing Jenkins and Jmeter to build a scalable Load Testing solution
Using Jenkins and Jmeter to build a scalable Load Testing solutionRuslan Strazhnyk
 
Performance Testing With Jmeter
Performance Testing With JmeterPerformance Testing With Jmeter
Performance Testing With JmeterAdam Goucher
 
An Introduction to Akka http
An Introduction to Akka httpAn Introduction to Akka http
An Introduction to Akka httpKnoldus Inc.
 
Practical Akka HTTP - introduction
Practical Akka HTTP - introductionPractical Akka HTTP - introduction
Practical Akka HTTP - introductionŁukasz Sowa
 
Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPRafal Gancarz
 
Building scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTPBuilding scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTPdatamantra
 
Lessons Learned From Running Spark On Docker
Lessons Learned From Running Spark On DockerLessons Learned From Running Spark On Docker
Lessons Learned From Running Spark On DockerSpark Summit
 
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickBuilding a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickZalando Technology
 
Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster OpenCredo
 
Jmeter Performance Testing
Jmeter Performance TestingJmeter Performance Testing
Jmeter Performance TestingAtul Pant
 
What's new in Zimbra Collaboration 8.7.x
What's new in Zimbra Collaboration 8.7.xWhat's new in Zimbra Collaboration 8.7.x
What's new in Zimbra Collaboration 8.7.xZimbra
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scaladatamantra
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyBozhidar Bozhanov
 

Viewers also liked (20)

Scala, docker and testing, oh my! mario camou
Scala, docker and testing, oh my! mario camouScala, docker and testing, oh my! mario camou
Scala, docker and testing, oh my! mario camou
 
Unsucking Error Handling with Futures
Unsucking Error Handling with FuturesUnsucking Error Handling with Futures
Unsucking Error Handling with Futures
 
Continous delivery - lad koden flyde 2014
Continous delivery - lad koden flyde 2014Continous delivery - lad koden flyde 2014
Continous delivery - lad koden flyde 2014
 
Automated Performance Testing With J Meter And Maven
Automated  Performance  Testing With  J Meter And  MavenAutomated  Performance  Testing With  J Meter And  Maven
Automated Performance Testing With J Meter And Maven
 
Akka Http , Routes, Streams with Scala
Akka Http , Routes, Streams with ScalaAkka Http , Routes, Streams with Scala
Akka Http , Routes, Streams with Scala
 
Using Jenkins and Jmeter to build a scalable Load Testing solution
Using Jenkins and Jmeter to build a scalable Load Testing solutionUsing Jenkins and Jmeter to build a scalable Load Testing solution
Using Jenkins and Jmeter to build a scalable Load Testing solution
 
Performance Testing With Jmeter
Performance Testing With JmeterPerformance Testing With Jmeter
Performance Testing With Jmeter
 
Akka http 2
Akka http 2Akka http 2
Akka http 2
 
An Introduction to Akka http
An Introduction to Akka httpAn Introduction to Akka http
An Introduction to Akka http
 
Practical Akka HTTP - introduction
Practical Akka HTTP - introductionPractical Akka HTTP - introduction
Practical Akka HTTP - introduction
 
Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTP
 
Building scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTPBuilding scalable rest service using Akka HTTP
Building scalable rest service using Akka HTTP
 
Lessons Learned From Running Spark On Docker
Lessons Learned From Running Spark On DockerLessons Learned From Running Spark On Docker
Lessons Learned From Running Spark On Docker
 
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickBuilding a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & Slick
 
Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster
 
Jmeter Performance Testing
Jmeter Performance TestingJmeter Performance Testing
Jmeter Performance Testing
 
What's new in Zimbra Collaboration 8.7.x
What's new in Zimbra Collaboration 8.7.xWhat's new in Zimbra Collaboration 8.7.x
What's new in Zimbra Collaboration 8.7.x
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 
Node.js vs Play Framework
Node.js vs Play FrameworkNode.js vs Play Framework
Node.js vs Play Framework
 

Similar to Ship your Scala code often and easy with Docker

Into to Docker (Central PA Java User Group - 8/14/2017)
Into to Docker (Central PA Java User Group - 8/14/2017)Into to Docker (Central PA Java User Group - 8/14/2017)
Into to Docker (Central PA Java User Group - 8/14/2017)Mike Melusky
 
Fabricio - Docker deploy automation
Fabricio - Docker deploy automationFabricio - Docker deploy automation
Fabricio - Docker deploy automationRinat Khabibiev
 
Docker Introductory workshop
Docker Introductory workshopDocker Introductory workshop
Docker Introductory workshopRuncy Oommen
 
DevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux ContainersDevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux Containersinside-BigData.com
 
Java microservicesdockerdockerhubusecase2
Java microservicesdockerdockerhubusecase2Java microservicesdockerdockerhubusecase2
Java microservicesdockerdockerhubusecase2Subramanyam Vemala
 
Clouds and Tools: Cheat Sheets & Infographics
Clouds and Tools: Cheat Sheets & InfographicsClouds and Tools: Cheat Sheets & Infographics
Clouds and Tools: Cheat Sheets & InfographicsThomas Poetter
 
How to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker BuildHow to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker BuildDocker, Inc.
 
Microservices DevOps on Google Cloud Platform
Microservices DevOps on Google Cloud PlatformMicroservices DevOps on Google Cloud Platform
Microservices DevOps on Google Cloud PlatformSunnyvale
 
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Docker, Inc.
 
How to Dockerize your Sitecore module
How to Dockerize your Sitecore moduleHow to Dockerize your Sitecore module
How to Dockerize your Sitecore moduleMihály Árvai
 
Baking docker using chef
Baking docker using chefBaking docker using chef
Baking docker using chefMukta Aphale
 
Baking Docker Using Chef - ChefConf 2015
Baking Docker Using Chef - ChefConf 2015Baking Docker Using Chef - ChefConf 2015
Baking Docker Using Chef - ChefConf 2015Chef
 
Docker for developers z java
Docker for developers z javaDocker for developers z java
Docker for developers z javaandrzejsydor
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안양재동 코드랩
 
Develop with docker 2014 aug
Develop with docker 2014 augDevelop with docker 2014 aug
Develop with docker 2014 augVincent De Smet
 

Similar to Ship your Scala code often and easy with Docker (20)

Into to Docker (Central PA Java User Group - 8/14/2017)
Into to Docker (Central PA Java User Group - 8/14/2017)Into to Docker (Central PA Java User Group - 8/14/2017)
Into to Docker (Central PA Java User Group - 8/14/2017)
 
How to _docker
How to _dockerHow to _docker
How to _docker
 
Fabricio - Docker deploy automation
Fabricio - Docker deploy automationFabricio - Docker deploy automation
Fabricio - Docker deploy automation
 
Docker Introductory workshop
Docker Introductory workshopDocker Introductory workshop
Docker Introductory workshop
 
DevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux ContainersDevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux Containers
 
Java microservicesdockerdockerhubusecase2
Java microservicesdockerdockerhubusecase2Java microservicesdockerdockerhubusecase2
Java microservicesdockerdockerhubusecase2
 
Clouds and Tools: Cheat Sheets & Infographics
Clouds and Tools: Cheat Sheets & InfographicsClouds and Tools: Cheat Sheets & Infographics
Clouds and Tools: Cheat Sheets & Infographics
 
How to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker BuildHow to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker Build
 
Dockercompose
DockercomposeDockercompose
Dockercompose
 
Microservices DevOps on Google Cloud Platform
Microservices DevOps on Google Cloud PlatformMicroservices DevOps on Google Cloud Platform
Microservices DevOps on Google Cloud Platform
 
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
 
How to Dockerize your Sitecore module
How to Dockerize your Sitecore moduleHow to Dockerize your Sitecore module
How to Dockerize your Sitecore module
 
Play on Docker
Play on DockerPlay on Docker
Play on Docker
 
Baking docker using chef
Baking docker using chefBaking docker using chef
Baking docker using chef
 
Baking Docker Using Chef - ChefConf 2015
Baking Docker Using Chef - ChefConf 2015Baking Docker Using Chef - ChefConf 2015
Baking Docker Using Chef - ChefConf 2015
 
Docker for developers z java
Docker for developers z javaDocker for developers z java
Docker for developers z java
 
Introduction To Docker
Introduction To  DockerIntroduction To  Docker
Introduction To Docker
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안
 
Develop with docker 2014 aug
Develop with docker 2014 augDevelop with docker 2014 aug
Develop with docker 2014 aug
 
Docker From Scratch
Docker From ScratchDocker From Scratch
Docker From Scratch
 

Recently uploaded

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 

Recently uploaded (20)

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 

Ship your Scala code often and easy with Docker

  • 1. Ship your Scala code often and easy with Docker Marcus Lönnberg marcus@lonnberg.nu github.com/marcuslonnberg @lonnbergm
  • 3.
  • 4. Agenda • Intro to Docker • Building Docker images with sbt • Manage Docker containers with Scala • Docker.at(SpeedLedger)
  • 5.
  • 6. Platform Open source Client - server REST API Immutable images Container virtualization
  • 9. Docker image Dockerfile Container > docker build --tag=myimage > docker run myimage
  • 11. Building and shipping Docker images Machine 1 Dockerfile + files Machine x > docker pull myimage > docker run myimage Registry > docker build --tag=myimage > docker push myimage Machine xMachine x
  • 13. Manually building a Scala application as a Docker image 1. Produce a fat JAR 2. Define a Dockerfile 3. Build a Docker image
  • 14. 0. Current sbt build name := "fancy-service"
 organization := "demo"
 
 libraryDependencies ++= Seq(
 "com.typesafe.akka" %% "akka-actor" % "2.3.9",
 "io.spray" %% "spray-routing" % “1.3.3”, ...
 ) build.sbt
  • 15. 1. sbt-assembly gives us a fat JAR project/plugins.sbt > sbt assembly … [info] Packaging out/fancy-service.jar ... … [success] Total time: 6 s addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.13.0")
  • 16. 2. Define a Dockerfile FROM ubuntu RUN apt-get update RUN apt-get install -y openjdk-8-jre-headless COPY fancy-service.jar /app/fancy-service.jar WORKDIR /app ENTRYPOINT java -jar fancy-service.jar EXPOSE 8080 Dockerfile
  • 17. 2. Define a Dockerfile FROM ubuntu RUN apt-get update RUN apt-get install -y openjdk-8 COPY fancy-service.jar WORKDIR /app ENTRYPOINT java -jar fancy-service.jar EXPOSE 8080 Dockerfile FROM java:8-jre WORKDIR /app EXPOSE 8080 ENTRYPOINT java -jar fancy-service.jar COPY fancy-service.jar /app/fancy-service.jar good
  • 18. 3. Building a Docker image > docker build -t demo/fancy-service . Sending build context to Docker daemon Step 0 : FROM java:8-jre ---> 028f36974b77 Step 1 : WORKDIR /app ---> fb8108515091 Step 2 : EXPOSE 8080 ---> 9512be4df795 Step 3 : ENTRYPOINT java -jar fancy-service.jar ---> 839dd75f5a96 Step 4 : COPY fancy-service.jar /app/fancy-service.jar ---> 948eb875c3b1 Removing intermediate container f9eeb9406fc7 Successfully built 948eb875c3b1
  • 20. sbt-docker addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.1.0") project/plugins.sbt enablePlugins(DockerPlugin) build.sbt
  • 21. Dockerfile DSL def jarFile: File def jarName: String
 
 new Dockerfile {
 from("java:8-jre")
 workDir("/app")
 expose(8080)
 entryPointRaw(s"java -jar $jarName")
 copy(jarFile, s"/app/$jarName")
 }
  • 22. Putting it all together docker <<= docker.dependsOn(assembly)
 
 dockerfile in docker := {
 val jarFile = (assemblyOutputPath in assembly).value
 val jarName = name.value + ".jar" 
 new Dockerfile {
 from("java:8-jre")
 workDir("/app")
 expose(8080)
 entryPointRaw(s"java -jar $jarName")
 copy(jarFile, s"/app/$jarName")
 }
 } build.sbt
  • 23. Let’s build an image > sbt docker … [info] Packaging out/fancy-service.jar ... … [info] Step 0 : FROM java:8-jre [info] ---> 028f36974b77 … [info] Successfully built 30c376822ced [info] Tagging image 30c376822ced with name: demo/fancy-service:0.1-SNAPSHOT [info] Tagging image 30c376822ced with name: demo/fancy-service:latest [success] Total time: 20 s
  • 24. Image names imageNames in docker := Seq(
 ImageName("demo/fancy-service:" + version.value),
 ImageName("demo/fancy-service:latest")
 ) build.sbt
  • 25. Immutable Dockerfile def jarFile: File def jarName: String
 
 Dockerfile.empty
 .from("java:8-jre")
 .workDir("/app")
 .expose(8080)
 .entryPointRaw(s"java -jar $jarName")
 .copy(jarFile, s"/app/$jarName")
  • 26. Build options buildOptions in docker := BuildOptions(
 cache = true,
 removeIntermediateContainers = BuildOptions.Remove.OnSuccess,
 pullBaseImage = BuildOptions.Pull.Always
 ) build.sbt
  • 27. sbt-docker • Define Dockerfiles with a DSL • Dynamically name your images • Push images to a registry github.com/marcuslonnberg/sbt-docker
  • 34. Build pipeline Dev machine Build server Test Production Registry git repo > git push > sbt dockerBuildAndPush > docker pull image Dev machine
  • 35. Tagging Docker images with git imageNames in docker := Seq(
 ImageName("demo/fancy-service:" + git.gitHeadCommit.value.get),
 ImageName("demo/fancy-service:" + git.gitCurrentBranch.value)
 )
  • 36. Labels with build info val labels = Map(
 "build.commitId" -> git.gitHeadCommit.value.get,
 "build.branch" -> git.gitCurrentBranch.value,
 "build.appName" -> name.value,
 "build.buildTime" -> Platform.currentTime.toString
 )
 
 new Dockerfile {
 …
 label(labels)
 …
 } Docker >= 1.6
  • 37. Internal sbt plugin • Adds common libraries • Generates build info • Configures logging • Adds monitoring • Sets good runtime properties • Defines a Dockerfile template
  • 38.
  • 39. What we have learned • Order instructions in Dockerfiles for fast builds • Docker is very easy to use except for networking and 
 file persistence • Define own base images but use official when ones exist • Building tools around Docker is easy and fun
  • 40. Links • github.com/marcuslonnberg/sbt-docker • github.com/marcuslonnberg/scala-docker • github.com/sbt/sbt-assembly • github.com/sbt/sbt-native-packager