【发布时间】:2017-05-22 20:36:40
【问题描述】:
我正在尝试使用 docker 运行 Scala 应用程序。我创建了一个具有以下结构的示例项目。
build.sbt
name := "test"
version := "1.0"
scalaVersion := "2.12.2"
project/build.properties
sbt.version = 0.13.15
src/main/scala/HelloWorld.scala
object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
现在,如果我使用 sbt run,一切正常,我收到了可爱的 hello-world 问候语。
$ sbt run
...
[info] Set current project to test (in build file:/Users/yuchen/Documents/test/)
[info] Running HelloWorld
Hello, world!
[success] Total time: 1 s, completed 22-May-2017 4:30:28 PM
我添加了一个 Dockerfile:
FROM openjdk:8
ENV SCALA_VERSION 2.12.2
ENV SBT_VERSION 0.13.15
RUN touch /usr/lib/jvm/java-8-openjdk-amd64/release
RUN \
curl -fsL http://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz | tar xfz - -C /root/ && \
echo >> /root/.bashrc && \
echo 'export PATH=~/scala-$SCALA_VERSION/bin:$PATH' >> /root/.bashrc
RUN \
curl -L -o sbt-$SBT_VERSION.deb http://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
dpkg -i sbt-$SBT_VERSION.deb && \
rm sbt-$SBT_VERSION.deb && \
apt-get update && \
apt-get install sbt && \
sbt sbtVersion
WORKDIR /root
CMD sbt run
它们都是从https://hub.docker.com/r/hseeberger/scala-sbt/~/dockerfile/ 复制而来的,最后一行是CMD sbt run。
我尝试运行 docker 命令:
docker build -t test .
docker tag test test/test:1.0
docker run test/test:1.0
但是,我不断收到此错误:
[info] Set current project to root (in build file:/root/)
[info] Updating {file:/root/}root...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
java.lang.RuntimeException: No main class detected.
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) No main class detected.
[error] Total time: 0 s, completed May 23, 2017 4:00:19 AM
这是什么意思,我该如何解决?
仅供参考:我知道http://www.scala-sbt.org/sbt-native-packager/formats/docker.html,但我只是想尝试编写 Dockerfile,因为我正在学习这个。
【问题讨论】:
-
您的调试输出对我来说没有意义。这些实际上是使用的命令吗?容器的输出是说它在
build.properties文件/Users/yuchen/Documents/test/中找不到sbt.version。但是Dockerfile不会将任何内容复制到任何文件夹中,并且运行命令不会挂载任何卷。错误应该改为显示file:/root/。 -
嘿@AndyShinn 抱歉,我正在尝试随机的事情,其中之一是将
/root更改为我的实际工作目录。显然,这并没有解决问题。我用WORKDIR /root再次运行了命令并更新了输出日志。有什么想法或建议这里有什么问题吗?