Reputation: 151
I'm learning to make docker image of scala application using sbt-native-packager. My application contains akka-http and running fine on localhost:8080 (scala-version: 2.13.1, sbt-version: 1.2.8). Now for making docker image. First I make 'plugins.sbt'.
projects/plugins.sbt:
resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.2")
Then I enable plugins in 'build.sbt'.
build.sbt:
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.1"
lazy val root = (project in file("."))
.settings(
name := "book_system_task"
)
enablePlugins(
JavaAppPackaging,
DockerPlugin
)
Compile / mainClass := Some("server.Server")
Docker / packageName := "testImage/book-system-task"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.6.0",
"com.typesafe.akka" %% "akka-stream" % "2.7.0",
"com.typesafe.akka" %% "akka-http" % "10.5.0",
"ch.qos.logback" % "logback-classic" % "1.4.4",
"com.typesafe.akka" %% "akka-http-spray-json" % "10.5.0",
"com.google.inject" % "guice" % "5.1.0",
"com.typesafe.akka" %% "akka-stream-testkit" % "2.7.0",
"com.typesafe.akka" %% "akka-http-testkit" % "10.5.0",
"org.scalatest" %% "scalatest" % "3.2.11",
"com.outworkers" %% "phantom-dsl" % "2.59.0"
)
Now I have to run 'sbt docker:publishLocal' (I'm confused where to run this command in intellij idea), I run this command(docker:publishLocal) in sbt-shell.
Output after running 'docker:publishLocal' in sbt-shell:
docker:publishLocal
[info] Packaging /home/zaryab/Downloads/book_system_task/target/scala-2.13/book_system_task_2.13-0.1.0-SNAPSHOT-sources.jar ...
[info] Wrote /home/zaryab/Downloads/book_system_task/target/scala-2.13/book_system_task_2.13-0.1.0-SNAPSHOT.pom
[info] Done packaging.
[info] Updating ...
[info] Done updating.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[info] Main Scala API documentation to /home/zaryab/Downloads/book_system_task/target/scala-2.13/api...
[info] Compiling 30 Scala sources to /home/zaryab/Downloads/book_system_task/target/scala-2.13/classes ...
model contains 60 documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /home/zaryab/Downloads/book_system_task/target/scala-2.13/book_system_task_2.13-0.1.0-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] Done compiling.
[info] Packaging /home/zaryab/Downloads/book_system_task/target/scala-2.13/book_system_task_2.13-0.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[info] :: delivering :: book_system_task#book_system_task_2.13;0.1.0-SNAPSHOT :: 0.1.0-SNAPSHOT :: integration :: Fri Apr 14 11:59:55 PKT 2023
[info] delivering ivy file to /home/zaryab/Downloads/book_system_task/target/scala-2.13/ivy-0.1.0-SNAPSHOT.xml
[info] published book_system_task_2.13 to /home/zaryab/.ivy2/local/book_system_task/book_system_task_2.13/0.1.0-SNAPSHOT/poms/book_system_task_2.13.pom
[info] published book_system_task_2.13 to /home/zaryab/.ivy2/local/book_system_task/book_system_task_2.13/0.1.0-SNAPSHOT/jars/book_system_task_2.13.jar
[info] published book_system_task_2.13 to /home/zaryab/.ivy2/local/book_system_task/book_system_task_2.13/0.1.0-SNAPSHOT/srcs/book_system_task_2.13-sources.jar
[info] published book_system_task_2.13 to /home/zaryab/.ivy2/local/book_system_task/book_system_task_2.13/0.1.0-SNAPSHOT/docs/book_system_task_2.13-javadoc.jar
[info] published ivy to /home/zaryab/.ivy2/local/book_system_task/book_system_task_2.13/0.1.0-SNAPSHOT/ivys/ivy.xml
[success] Total time: 9 s
But still after this, I'm not able to see where Dockerfile is created. Or Docker Image/File is created or not.
Upvotes: 0
Views: 626
Reputation: 3488
As you can see in the docs of sbt-native-packager, you have 4 tasks that you can execute.
docker:publishLocal
: will build the image and publish in your local docker server. Based on your output, looks like you have already installed it. Just running docker images
from the terminal you should be able to see an image with the name testImage/book-system-task
.If you want to generate a Dockerfile, you should use the task docker:stage
. The output of executing that task will tell you where the file is located
Upvotes: 2