2

I want to start a play framework 2 application in a Dockerfile.

Let us assume my play project rests in the /myapp directory in ubuntu. When I start it manually, I would just say:

cd /myapp
sbt run

How can I run sbt run on it from the CMD command of the Dockerfile?

Running sbt run has to be from within the /myapp directory. How do I tell the CMD command that sbt run should be run from that directory?

2 Answers 2

13

Take a closer look at the new experimental docker feature for the sbt-native-packager.

You should be able to build a docker container from your play application with a few simple steps. Adding a maintainer and the exposed ports

import NativePackagerKeys._ // with auto plugins this won't be necessary soon

name := "play-2.3"

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
  jdbc,
  anorm,
  cache,
  ws
)

// setting a maintainer which is used for all packaging types
maintainer := "Nepomuk Seiler"

// exposing the play ports
dockerExposedPorts in Docker := Seq(9000, 9443)

and then run

sbt docker:publishLocal
docker run -p 9000:9000 play-2-3:1.0-SNAPSHOT 

Update - 1.x version

With sbt-native-packager 1.x ( and so with play 2.4.x ) docker is enabled by default ( because play enables the JavaServerAppPackaging plugin ).

If you don't have a play application then enable docker with

enablePlugins(JavaAppPackagingPlugin)

maintainer := "Nepomuk Seiler"
// note that the Docker scope is gone!
dockerExposedPorts := Seq(9000, 9443)
2
  • This is not working for me: docker run -p 9000:9000 dragisak/demo:1.0-SNAPSHOT bin/demo: line 17: dirname: command not found bin/demo: line 18: basename: command not found Commented Aug 8, 2014 at 5:08
  • Please open an issue on github.com/sbt/sbt-native-packager/issues with a small example reproducing your error.
    – Muki
    Commented Aug 13, 2014 at 18:38
1

You can just connect both statements:

FROM ubuntu

... more Dockerfile commands...

CMD cd /myapp && sbt run

You could also use the WORKDIR command of Dockerfiles (see http://docs.docker.io/reference/builder/#workdir) to set the working directory for your CMD command. But I never used this for myself (with no specific reason...):

FROM ubuntu

... more Dockerfile commands...

WORKDIR /myapp
CMD sbt run

Not the answer you're looking for? Browse other questions tagged or ask your own question.