How copy resources files with sbt docker plugin

I’m running an application using docker which crashes because my application cannot access to a file located in the folder src/main/resources. Here my file project/plugins.sbt :

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.1.4")

my build.sbt file :

  • How to run the COPY and RUN command in same container?
  • Block port from the outside except for Docker
  • Docker Volumes - bind mount different filesystem to ../docker/volumes/
  • Docker - Use IP instead of --link for communication
  • Can't start docker with postgres
  • Push docker image to amazon ecs repository
  • organization      := """foo"""
    name              := """bar"""
    version           := "1.0"
    scalaVersion := "2.11.7"
    libraryDependencies ++= Seq(
      "org.apache.kafka" % "kafka_2.10" % "",
      "org.scalatest" % "scalatest_2.11" % "3.0.0-M16-SNAP1",
      "org.scalaz" %% "scalaz-core" % "7.2.5",
      "com.typesafe.akka" %% "akka-actor" % "2.4.11",
      "" % "play-json_2.11" % "2.4.8",
      "com.typesafe.scala-logging" %% "scala-logging" % "3.1.0",
      "com.typesafe" % "config" % "1.3.0",
      "com.amazonaws" % "aws-java-sdk" % "1.11.8",
      "ch.qos.logback" % "logback-classic" % "1.1.7",
      "com.typesafe.akka" % "akka-testkit_2.11" % "2.4.12"
    // the default value in sbt is set to true 
    parallelExecution in Test := false 
    resolvers += "Sonatype OSS Snapshots" at ""
    dependencyOverrides ++= Set(
      "com.fasterxml.jackson.core" % "jackson-databind" % "2.4.4"
    resolvers ++= Seq(
      "Sonatype Snapshots" at "",
      "Sonatype Releases" at ""
    enablePlugins(DockerPlugin, JavaAppPackaging)
    // enablePlugins(JavaAppPackaging)
    packageName in Docker := "foo/bar"

    Here the main file :

    object FGS_MainApp extends LazyLogging {
      val actorSystemName = "SYS"
      println("Create actor sys " + actorSystemName)
      val system = ActorSystem(actorSystemName)
      private val t = new Thread { 
        override def run() = {
          if (system != null) {
      def main(args : Array[String]) = {
        // TODO : this needs to be remove quickly
        val saslPath = getClass.getResource("/sasl.conf").getPath
        println("saslPath = " + saslPath)
        System.setProperty("", saslPath)

    Then when I’m running the command : sbt docker:publishLocal && docker run -it foo/bar:1.0, I got this error :

    Caused by: java.lang.SecurityException: Configuration Error:
        No such file or directory

    The printed path is :


    What did I miss with the configuration in build.sbt ?


    Caused by: org.apache.kafka.common.KafkaException: java.lang.SecurityException: Configuration Error:
        No such file or directory
        at org.apache.kafka.clients.ClientUtils.createChannelBuilder(
        at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(
        ... 18 more
    Caused by: java.lang.SecurityException: Configuration Error:
        No such file or directory
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
        at java.lang.reflect.Constructor.newInstance(
        at java.lang.Class.newInstance(
        at Method)
        ... 21 more
    Caused by: Configuration Error:
        No such file or directory
        ... 35 more

    And it shows the line :

    private val kafkaConsumer = new KafkaConsumer[String, Array[Byte]](kafkaProps) where kafkaProps is type of java.util.Properties. So it cannot find the file in resources folder.

  • Run postgres container with data volumes through docker-machine
  • How to sync the time of a java application running on docker container?
  • Connect to Remote MSSQL db from Linux Docker container
  • Link Docker containers running on different hosts?
  • Killbill on Google Flexible Environment using Java and Cloud SQL
  • Docker Gradle project generates single JAR, but keeps rebuilding 4 layers
  • One Solution collect form web for “How copy resources files with sbt docker plugin”

    The problem you’re encountering is with how src/main/resources is treated. It’s a special folder whose contents will be included in the jar file built by sbt. It’s never actually copied as a file into your universal package. That’s why the file path that’s printed out includes the jar name and a ! – that means the file is inside the zipped jar. It’s clear that the kafka library doesn’t handle this.

    To solve this, you should put the file in a different location, like src/main/conf (optional, but strictly-speaking more correct), then map it into your universal package: +=
      ((sourceDirectory.value / "main" / "conf" / "sasl.conf"), "conf/sasl.conf"))

    This will now be available as the file conf/sasl.conf within your universal package.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.