gpt4 book ai didi

scala - 如何使用 sbt-docker 或手动编写 docker 文件在 docker 中运行 sbt 项目?

转载 作者:行者123 更新时间:2023-12-02 18:44:50 25 4
gpt4 key购买 nike

我一直在尝试学习在 docker 中运行一个 sbt 项目。我也想用喷雾。
我正在关注 sbt-docker 在 github 中提供的示例:
https://github.com/marcuslonnberg/sbt-docker/tree/master/examples/package-spray
当我拉取项目时,它工作正常,我也可以运行 docker 容器。

项目>项目> PackageSprayBuild.scala中有一个文件
我不知道这个文件是如何被使用的。
此外,给定的示例没有 plugins.sbt 文件。

然后我尝试创建我的单独项目。

我的 plugins.sbt 看起来像这样:

logLevel := Level.Warn

addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.2.0")

我的 build.sbt 看起来与我上面提到的示例几乎相同。
name := "demo-docker-sbt"

version := "1.0"

scalaVersion := "2.11.7"

resolvers += "spray repo" at "http://repo.spray.io/"

libraryDependencies ++= Seq(
"io.spray" % "spray-can" % "1.2.0",
"io.spray" % "spray-routing" % "1.2.0",
"com.typesafe.akka" %% "akka-actor" % "2.2.3")

enablePlugins(DockerPlugin)

// Make docker depend on the package task, which generates a jar file of the application code
docker <<= docker.dependsOn(Keys.`package`.in(Compile, packageBin))

// Define a Dockerfile
dockerfile in docker := {
val jarFile = artifactPath.in(Compile, packageBin).value
val classpath = (managedClasspath in Compile).value
val mainclass = mainClass.in(Compile, packageBin).value.get
val libs = "/app/libs"
val jarTarget = "/app/" + jarFile.name

new Dockerfile {
// Use a base image that contain Java
from("java")
// Expose port 8080
expose(8080)

// Copy all dependencies to 'libs' in the staging directory
classpath.files.foreach { depFile =>
val target = file(libs) / depFile.name
stageFile(depFile, target)
}
// Add the libs dir from the
addRaw(libs, libs)

// Add the generated jar file
add(jarFile, jarTarget)
// The classpath is the 'libs' dir and the produced jar file
val classpathString = s"$libs/*:$jarTarget"
// Set the entry point to start the application using the main class
cmd("java", "-cp", classpathString, mainclass)
}
}

然后我进入终端,在项目内部并使用命令“sbt docker”,然后它给了我以下错误:
[info] Resolving com.typesafe.akka#akka-actor_2.11;2.2.3 ...
[warn] module not found: com.typesafe.akka#akka-actor_2.11;2.2.3
[warn] ==== local: tried
[warn] /home/admin/.ivy2/local/com.typesafe.akka/akka-actor_2.11/2.2.3/ivys/ivy.xml
[warn] ==== jcenter: tried
[warn] https://jcenter.bintray.com/com/typesafe/akka/akka-actor_2.11/2.2.3/akka-actor_2.11-2.2.3.pom
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/com/typesafe/akka/akka-actor_2.11/2.2.3/akka-actor_2.11-2.2.3.pom
[warn] ==== spray repo: tried
[warn] http://repo.spray.io/com/typesafe/akka/akka-actor_2.11/2.2.3/akka-actor_2.11-2.2.3.pom
[info] Resolving jline#jline;2.12.1 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.typesafe.akka#akka-actor_2.11;2.2.3: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Unresolved dependencies path:
[warn] com.typesafe.akka:akka-actor_2.11:2.2.3 (/home/admin/IdeaProjects/demo-docker-sbt/build.sbt#L11-15)
[warn] +- default:demo-docker-sbt_2.11:1.0
sbt.ResolveException: unresolved dependency: com.typesafe.akka#akka-actor_2.11;2.2.3: not found
at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:291)
at sbt.IvyActions$$anonfun$updateEither$1.apply(IvyActions.scala:188)
at sbt.IvyActions$$anonfun$updateEither$1.apply(IvyActions.scala:165)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:155)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:155)
at sbt.IvySbt$$anonfun$withIvy$1.apply(Ivy.scala:132)
at sbt.IvySbt.sbt$IvySbt$$action$1(Ivy.scala:57)
at sbt.IvySbt$$anon$4.call(Ivy.scala:65)
at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:93)
at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:78)
at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:97)
at xsbt.boot.Using$.withResource(Using.scala:10)
at xsbt.boot.Using$.apply(Using.scala:9)
at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:58)
at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:48)
at xsbt.boot.Locks$.apply0(Locks.scala:31)
at xsbt.boot.Locks$.apply(Locks.scala:28)
at sbt.IvySbt.withDefaultLogger(Ivy.scala:65)
at sbt.IvySbt.withIvy(Ivy.scala:127)
at sbt.IvySbt.withIvy(Ivy.scala:124)
at sbt.IvySbt$Module.withModule(Ivy.scala:155)
at sbt.IvyActions$.updateEither(IvyActions.scala:165)
at sbt.Classpaths$$anonfun$sbt$Classpaths$$work$1$1.apply(Defaults.scala:1369)
at sbt.Classpaths$$anonfun$sbt$Classpaths$$work$1$1.apply(Defaults.scala:1365)
at sbt.Classpaths$$anonfun$doWork$1$1$$anonfun$87.apply(Defaults.scala:1399)
at sbt.Classpaths$$anonfun$doWork$1$1$$anonfun$87.apply(Defaults.scala:1397)
at sbt.Tracked$$anonfun$lastOutput$1.apply(Tracked.scala:37)
at sbt.Classpaths$$anonfun$doWork$1$1.apply(Defaults.scala:1402)
at sbt.Classpaths$$anonfun$doWork$1$1.apply(Defaults.scala:1396)
at sbt.Tracked$$anonfun$inputChanged$1.apply(Tracked.scala:60)
at sbt.Classpaths$.cachedUpdate(Defaults.scala:1419)
at sbt.Classpaths$$anonfun$updateTask$1.apply(Defaults.scala:1348)
at sbt.Classpaths$$anonfun$updateTask$1.apply(Defaults.scala:1310)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:235)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] (*:update) sbt.ResolveException: unresolved dependency: com.typesafe.akka#akka-actor_2.11;2.2.3: not found

问题:

1)。这里应该使用什么版本的akka​​,在docker容器中正确运行sbt项目我缺少什么?我的 build.sbt docker 配置有什么需要更改的吗?

我的 sbt 是 0.13.8,scala 2.11.7

2)示例项目中那个PackageSprayBuild.scala文件有什么用,为什么没有使用plugins.sbt文件?

3)。在项目的 docker 中构建镜像之前,我是否还必须在 sbt 项目中定义一个主类?或者我可以通过提供 build.sbt 和 plugins.sbt 配置来简单地构建图像吗?

4)。如果我想在不使用 sbt-native-packager 或 sbt-docker 或 sbt-assembly 的情况下为我的 sbt-project 手动构建 docker 镜像,那么示例 docker 文件是什么?我已经阅读了 dockerfile 引用,但无法准确了解如何为 sbt 项目特别定义 docker 文件。一个示例将非常有助于显示构建图像的命令以及该 docker 文件的内容。

5)。似乎有多种方法可以在 docker 容器内运行 sbt 项目。哪种方法是实现它的最佳方法,为什么?
我想将 sbt 与喷雾/Play Framework 一起使用并在许多容器中运行它。

我正在使用 Lubuntu 操作系统。

最佳答案

关于scala - 如何使用 sbt-docker 或手动编写 docker 文件在 docker 中运行 sbt 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34384657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com