2

I am trying to build a Docker image on a Play 2.2 project. I am using Docker version 1.2.0 on Ubuntu Linux.

My Docker specific settings in Build.scala looks like this:

dockerBaseImage in Docker := "dockerfile/java:7"
maintainer in Docker := "My name"
dockerExposedPorts in Docker := Seq(9000, 9443)
dockerExposedVolumes in Docker := Seq("/opt/docker/logs")

Generated Dockerfile:

FROM dockerfile/java:latest
MAINTAINER 
ADD files /
WORKDIR /opt/docker
RUN ["chown", "-R", "daemon", "."]
USER daemon
ENTRYPOINT ["bin/device-guides"]
CMD []

Output looks like the dockerBaseImage is being ignored, and the default

(dockerfile/java:latest) is not handled correctly:
[project] $ docker:publishLocal
[info] Wrote /..../project.pom
[info] Step 0 : FROM dockerfile/java:latest
[info]  ---> bf7307ff060a
[info] Step 1 : MAINTAINER
[error] 2014/10/07 11:30:12 Invalid Dockerfile format
[trace] Stack trace suppressed: run last docker:publishLocal for the full output.
[error] (docker:publishLocal) Nonzero exit value: 1
[error] Total time: 2 s, completed Oct 7, 2014 11:30:12 AM
[project] $ run last docker:publishLocal
java.lang.RuntimeException: Invalid port argument: last
    at scala.sys.package$.error(package.scala:27)
    at play.PlayRun$class.play$PlayRun$$parsePort(PlayRun.scala:52)
    at play.PlayRun$$anonfun$play$PlayRun$$filterArgs$2.apply(PlayRun.scala:69)
    at play.PlayRun$$anonfun$play$PlayRun$$filterArgs$2.apply(PlayRun.scala:69)
    at scala.Option.map(Option.scala:145)
    at play.PlayRun$class.play$PlayRun$$filterArgs(PlayRun.scala:69)
    at play.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$1.apply(PlayRun.scala:97)
    at play.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$1.apply(PlayRun.scala:91)
    at scala.Function7$$anonfun$tupled$1.apply(Function7.scala:35)
    at scala.Function7$$anonfun$tupled$1.apply(Function7.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Invalid port argument: last
[error] Total time: 0 s, completed Oct 7, 2014 11:30:16 AM

What needs to be done to make this work?

I am able to build the image using Docker from the command line:

docker build --force-rm -t device-guides:1.0-SNAPSHOT .
2
  • Can you give the docker version you are using and the Dockerfile which is created?
    – Muki
    Commented Oct 7, 2014 at 22:42
  • @Muki, I added Docker version and details to question.
    – rvange
    Commented Oct 8, 2014 at 6:20

2 Answers 2

2

Packaging/publishing settings are per-project settings, rather than per-build settings.

You were using a Build.scala style build, with a format like this:

object ApplicationBuild extends Build { val main = play.Project(appName, appVersion, libraryDependencies).settings( ... ) }

The settings should be applied to this main project. This means that you call the settings() method on the project, passing in the appropriate settings to set up the packaging as you wish.

In this case:

object ApplicationBuild extends Build { val main = play.Project(appName, appVersion, libraryDependencies).settings( dockerBaseImage in Docker := "dockerfile/java:7", maintainer in Docker := "My name", dockerExposedPorts in Docker := Seq(9000, 9443), dockerExposedVolumes in Docker := Seq("/opt/docker/logs") ) }

To reuse similar settings across multiple projects, you can either create a val of type Seq[sbt.Setting], or extend sbt.Project to provide the common settings. See http://jsuereth.com/scala/2013/06/11/effective-sbt.html for some examples of how to do this (e.g. Rule #4).

This placement of settings is not necessarily clear if one is used to using build.sbt-type builds instead, because in that file, a line that evaluates to an SBT setting (or sequence of settings) is automatically appended to the root project's settings.

1

It's a wrong command you executed. I didn't saw it the first time.

run last docker:publishLocal

remove the run last

docker:publishLocal

Now you get your docker image build as expected

6
  • If you look closely, I start with executing docker:publishLocal. Afterwards I run it with run last, in order to get the error + exception stack trace.
    – rvange
    Commented Oct 13, 2014 at 8:37
  • omfg. you are right. Sorry for that :( Can you provide a small sample project to reproduce this, or is the build.sbt already complete?
    – Muki
    Commented Oct 13, 2014 at 19:57
  • I am using Play 2.2, which might be a problem, as I can get this Play 2.3 app to run easily github.com/CloudBees-community/play2-on-beanstalk
    – rvange
    Commented Oct 14, 2014 at 7:25
  • This is an interesting point. Using play 2.3 works? I'm not quite sure if they already added the native-packager-settings completely. try adding the packager_archetype.java_server
    – Muki
    Commented Oct 16, 2014 at 21:18
  • 1
    You have your Docker settings inside the Build object, not inside the project (these should be project settings). e.g. put these settings after the scalacOptions setting.
    – Gary Coady
    Commented Oct 17, 2014 at 15:18

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