Scala application dockerised
27 of April, 2017
There are tens of articles about dockerising Scala apps. Here is my take (or more of a note to future self).
Just add plugin to
and enable it in
build.sbt like this:
DockerPlugin enables building and publishing docker images.
AshScriptPlugin allows to build using image, which do not have bash included
(you probably can skip this one if not going to build on top of minimal alpine linux).
You don’t have to care about creating
Dockerfile - plugin will do this work for you (yay!).
At the minimum you only need to specify which port to expose.
There are more options, of course, see plugin documentation for others.
Below is an example of such configuration in
build.sbt (exposes, port, uses minimal image, sets version, repository and package names):
Once this is done:
sbt docker:publishLocalwill build and publish image into local environment. You can then use the package with a command like
docker run --rm -p"8080:8080" asarturas/someapp
sbt docker:publishis essentially the same as the above, with addition of publishing to the docker repository. By default it will attempt to publish to Docker Hub, so you will have to be logged into your account with
Pairing buddy is a sample app, built using this approach.comments powered by Disqus