forked from marcus-drake/sbt-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DockerfileExamples.scala
58 lines (43 loc) · 1.34 KB
/
DockerfileExamples.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.File
import sbtdocker.Instructions._
import sbtdocker._
import staging.CopyFile
// There is both a mutable and an immutable Dockerfile.
// Both share the same API where all Dockerfile instructions have a corresponding method.
val jarFile: File = ???
// An immutable Dockerfile
immutable.Dockerfile.empty
.from("ubuntu")
.run("apt-get", "-y", "install", "openjdk-7-jre-headless")
.add(jarFile, "/srv/app.jar")
.workDir("/srv")
.cmdRaw("java -jar app.jar")
// A mutable Dockerfile (which does the same as the immutable example)
new mutable.Dockerfile {
from("ubuntu")
run("apt-get", "-y", "install", "openjdk-7-jre-headless")
add(jarFile, "/srv/app.jar")
workDir("/srv")
cmdRaw("java -jar app.jar")
}
// Some benefits of the mutable Dockerfile is that it is easy to conditionally include instructions
// and adding instructions given a collection.
val numbers = List(1, 1, 2, 3, 5, 8)
val earthIsRound = true
new mutable.Dockerfile {
from("ubuntu")
if (earthIsRound) {
expose(80)
}
numbers foreach { n =>
run("echo", n.toString)
}
}
// A Dockerfile can also be created with a sequence of instructions
val instructions = Seq(
From("ubuntu"),
Run.exec(Seq("apt-get", "-y", "install", "openjdk-7-jre-headless")),
Add(CopyFile(jarFile), "app.jar"),
Cmd("java -jar app.jar")
)
Dockerfile(instructions)