0

I'm trying to use the sbt-native-packager to produce a Docker image of my Scala play app, I followed the steps described at http://www.scala-sbt.org/sbt-native-packager/formats/docker.html

This is my configuration:

on my plugins.sbt I added the dependency for sbt native packager:

// SBT Native
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.2.1")

on my build.sbt I added the plugins for Universal and Docker:

.enablePlugins(PlayScala, JavaAppPackaging)

I also added some extra properties:

javaOptions in Universal ++= Seq(
  // JVM memory tuning
  "-J-Xmx1024m",
  "-J-Xms512m",

  // Since play uses separate pidfile we have to provide it with a proper path
  // name of the pid file must be play.pid
  s"-Dpidfile.path=/var/run/${packageName.value}/play.pid",

  // Use separate configuration file for production environment
  s"-Dconfig.file=/usr/share/${packageName.value}/conf/production.conf",

  // Use separate logger configuration file for production environment
  s"-Dlogger.file=/usr/share/${packageName.value}/conf/logback.xml"
)

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

Then I generate the docker image using the plugin and SBT CLI:

docker:publishLocal

the dockerfile gets generated at ./target/docker/Dockerfile

when I inspect the file I see:

FROM openjdk:latest
WORKDIR /opt/docker
ADD opt /opt
RUN ["chown", "-R", "daemon:daemon", "."]
USER daemon
ENTRYPOINT ["bin/root"]
CMD []

which doesn't seem to contain all the necessary steps to run the app, when I use docker build . I get :

java.nio.file.NoSuchFileException: /var/run/root/play.pid

It seems like the Dockerfile is missing some steps where it should mkdir /var/run/{APP_NAME}/ (* creating folder inside docker container instance)

and chown that folder in order for play to create the PID file.

how to fix the above error ?

1 Answer 1

1

What's the error message when starting the docker image and how do you start it?

Then there are a couple of notable things.

play ships with native-packager

You shouldn't have to add any plugin, but only configure docker relevant stuff. You already linked the correct documentation for the package format ( docker ).

Archetypes Vs Formats

Your configuration won't work without the play plugin. Take a look at http://www.scala-sbt.org/sbt-native-packager/archetypes/java_app/index.html which explains how to configure a simple application build.

I'd also recommend to read the format and Archetypes section here: http://www.scala-sbt.org/sbt-native-packager/introduction.html#archetype-plugins

Native docker build

Native-packager currently generates two docker files, which is confusing and not relevant. Sorry for that confusion. We plan to remove the redundant docker file. Simply go one level deeper and run the docker build command.

Hope that helps, Muki

3
  • thanks for the additional info. I did review your links and I got a problem which my play app is not working out of the box, I added some more details above, and followed your suggestions, it seems that the resulting image from sbt-native-packager is missing the step where it creates the folder /var/run/{app_name}/ (PID file) do I need to add these steps as custom fields in my build.sbt ?
    – guilhebl
    Commented Aug 21, 2017 at 7:12
  • the Dockerfile tries to create a /var/run/${packageName.value}/ folder and gets permission denied, so I believe it should run as root ? Any suggestions for the above issues? Thanks.
    – guilhebl
    Commented Aug 21, 2017 at 22:31
  • 1
    You can disable the pid file by setting it to /dev/null. It's documented in the play application. It doesn't make sense to use a pid file with docker.
    – Muki
    Commented Sep 2, 2017 at 19:16

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