ADD/COPY files with sbt-native-packager's docker support ADD/COPY files with sbt-native-packager's docker support docker docker

ADD/COPY files with sbt-native-packager's docker support


I managed to get it to work by adding the file to mappings in Universal. So for you, you would need something like this:

mappings in Universal += file("test.txt") -> "keys/test.txt"

You won't need the COPY command if you do this, by the way.

Now, I'm not sure if this is going to add this mapping to other sbt-native-packager plugins. I hope a commenter can tell me whether or not this is true, but my intuition is that it will do so, which might be a dealbreaker for you. But any workaround is better than none, right? If you use Build.scala you could maybe use a VM argument to tell sbt whether or not to add this mapping...


You may place all additional files (which must be included in container image) into folder src/universal. Content of that folder will be automatically copied in /opt/app folder within your container image. You don't need any additional configuration. See "Getting started with Universal Packaging" for additional info.

The files located in /src/universal will be available in the runtime directory for the Scala app in the Docker container. This means that if your app has /src/universal/example.txt, then it can be accessed with scala.io.Source.fromFile("./example.txt")


I was able to get this working using dockerPackageMappings:

dockerPackageMappings in Docker += (baseDirectory.value / "docker" / "ssh_config") -> "ssh_config"dockerCommands := (dockerCommands.value match {  case Seq(from@Cmd("FROM", _), rest@_*) =>    Seq(     from,     Cmd("Add", "ssh_config", "/sbin/.ssh/config")  ) ++ rest})