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