"A way to pack, ship and run any application as a lightweight container"- From the Docker website
# apt-get install docker
(or equivalent command)
On OS/X and Windows:
Install Docker Toolbox which includes docker-machine.
Will use a VirtualBox VM to host the Docker containers
FROM java:openjdk-8-jre
RUN /usr/bin/apt-get update && \
/usr/bin/apt-get install -y locales git postgresql-client && \
/usr/bin/apt-get clean && \
/usr/sbin/locale-gen en_US en_US.UTF-8 && \
/usr/sbin/useradd -r -s /bin/false -d /srv appuser
COPY target/scala-2.11/myApp.jar /srv/myApp.jar
COPY bin/run-docker.sh /srv/run.sh
COPY lib/etc /srv/etc
RUN chown -R myUser /srv && chmod 0544 /srv/run.sh
USER myUser
ENTRYPOINT /srv/run.sh
$ docker build .
Sending build context to Docker daemon 78.2 MB
Sending build context to Docker daemon
Step 0 : FROM java:openjdk-8-jre
---> 45a4bb374fcb
Step 1 : RUN /usr/bin/apt-get update && /usr/bin/apt-get install -y locales git postgresql-client && /usr/bin/apt-get clean && /usr/sbin/locale-gen en_US en_US.UTF-8 && /usr/sbin/useradd -r -s /bin/false -d /srv appuser
---> Using cache
---> 01b419a0e4fe
Step 2 : WORKDIR /srv
---> Using cache
---> 0b4060deee6d
Step 3 : COPY target/scala_2.11/myApp.jar /srv/myApp.jar
---> Using cache
---> 5a2fdbe7988f
Step 4 : COPY bin/run-docker.sh bin/run.sh
---> Using cache
---> d298418084c5
Step 5 : COPY lib/etc etc
---> Using cache
---> 667c3afe09c5
Step 6 : RUN chown -R myUser /srv && chmod 0544 /srv/run.sh
---> Using cache
---> 239fa5c77ad0
Step 7 : USER myUser
---> Using cache
---> 848a559a8550
Step 8 : ENTRYPOINT /srv/run.sh
---> Using cache
---> 2a31f1128eee
Successfully built 2a31f1128eee
$ docker run 2a31f1128eee
$ docker push myOrg/myApp
$ docker pull myOrg/myApp
$ docker run myOrg/myApp:latest
java:openjdk-8
java
image
FROM java:8
FROM anapsix/alpine-java
RUN /usr/bin/apt-get update && \
/usr/bin/apt-get install -y locales git postgresql-client && \
/usr/bin/apt-get clean && \
/usr/sbin/locale-gen en_US en_US.UTF-8 && \
/usr/sbin/useradd -r -s /bin/false -d /home/appuser appuser
COPY
to add any .class or .jar filessbt-assembly
or sbt-native-packager
COPY target/scala-2.11/myApp.jar /home/appuser/lib
COPY bin/run-docker.sh /srv/run.sh
COPY etc /srv/etc
RUN chown -R myUser /srv && chmod 0544 /srv/run.sh
USER myUser
ENTRYPOINT /srv/run.sh
$ docker build
$ docker push myOrg/myApp
imageNames in docker := Seq(
ImageName(
namespace = Some("mcamou"),
repository = name.value,
tag = Some(s"v${version.value}")
),
ImageName(
namespace = Some("mcamou"),
repository = name.value
tag = Some("latest")
),
)
val artifact = (outputPath in assembly).value
val baseDir = "/srv"
val preInstall = Seq(
"/usr/bin/apt-get update",
"/usr/bin/apt-get install -y locales git postgresql-client",
"/usr/bin/apt-get clean",
"/usr/sbin/locale-gen en_US en_US.UTF-8",
s"/usr/sbin/useradd -r -s /bin/false -d $baseDir myUser"
).mkString(" && ")
dockerfile in docker := {
new Dockerfile {
from("java:openjdk-8-jre")
runRaw(preInstall)
copy(artifact, s"$baseDir/app.jar")
copy(new File("bin/run-docker.sh"), s"$baseDir/run.sh")
copy(new File("local/etc"), "$baseDir/etc")
runRaw("chown -R myUser $baseDir && chmod 0544 $baseDir/run.sh")
user("myUser")
entryPoint("bin/run.sh")
}
}
docker <<= (docker dependsOn assembly)
sbt> docker
sbt> dockerPush
sbt-assembly
or sbt-native-packager
docker-machine
and set up the environment variables before starting up sbt
$ docker-machine start theMachine
$ eval $(docker-machine env theMachine)
docker-it-scala
docker-it-scala
trait DockerMongodbService extends DockerKit {
val DefaultMongodbPort = 27017
val mongodbContainer = DockerContainer("mongo:2.6.5")
.withPorts(DefaultMongodbPort -> None)
.withReadyChecker(DockerReadyChecker.LogLine(
_.contains("waiting for connections on port")
))
.withCommand("mongod", "--nojournal", "--smallfiles", "--syncdelay", "0")
abstract override def dockerContainers: List[DockerContainer] =
mongodbContainer :: super.dockerContainers
}
docker-it-scala
class MyMongoSpec extends FlatSpec
with Matchers
with DockerMongodbService {
// Test assumes the MongoDB container is running
}
--net=host
)
akka.remote.netty.tcp.bind-hostname // Internal
akka.remote.netty.tcp.bind-port
akka.remote.netty.tcp.hostname // External
akka.remote.netty.tcp.port
docker -link
or docker network
akka-zk-cluster-seed
)reactive-docker
to control the Docker daemonreactive-docker
example
implicit val docker = Docker("localhost")
implicit def timeout: Duration = Duration(20, SECONDS)
val containerName = "reactive-docker"
val cmd = Seq("/bin/sh", "-c", "while true; do echo hello world; sleep 1; done")
val cfg = ContainerConfig("busybox", cmd)
val (containerId, _) = Await.result(docker.containerCreate("myOrg/myApp", cfg, Some(containerName)), timeout)
val started = await(docker.containerStart(containerId))
val stopped = await(docker.containerStop(containerId))