无法使用 sbt-native-packager 制作 docker 镜像

问题描述 投票:0回答:1

我正在学习使用 sbt-native-packager 制作 scala 应用程序的 docker 镜像。我的应用程序包含 akka-http 并且在 localhost:8080 上运行良好(scala 版本:2.13.1,sbt 版本:1.2.8)。现在制作 docker 镜像。首先我制作'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")

然后我在'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"
)

现在我必须运行'sbt docker:publishLocal'(我很困惑在intellij idea中在哪里运行这个命令),我在sbt-shell中运行这个命令(docker:publishLocal)。

在 sbt-shell 中运行 'docker:publishLocal' 后的输出:

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

但在此之后,我仍然看不到 Dockerfile 的创建位置。或者是否创建了 Docker 镜像/文件。

docker scala sbt sbt-native-packager
1个回答
0
投票

正如您在 sbt-native-packager 的文档中看到的,您可以执行 4 个任务。

  • docker:publishLocal
    :将构建图像并在本地 docker 服务器上发布。根据您的输出,看起来您已经安装了它。只需从终端运行
    docker images
    ,您应该能够看到名为
    testImage/book-system-task
    .
  • 的图像

如果你想生成一个Dockerfile,你应该使用任务

docker:stage
。执行该任务的输出将告诉您文件所在的位置

© www.soinside.com 2019 - 2024. All rights reserved.