不能从根目录 运行 sbt

cannot run sbt from root directory

我收到如下错误:

#8 46.51 [error] java.lang.IllegalStateException: cannot run sbt from root directory without -Dsbt.rootdir=true; see sbt/sbt#1458
#8 46.51 [error] Use 'last' for the full log.

Dockerfile 大部分只是下载和安装 debian。但是有些事情让 sbt 不开心。不知道是什么。

FROM openjdk:8 as build
ENV SBT_VERSION "1.5.8"
ENV APP_HOME /service
# Install sbt
RUN \
  curl -L -o sbt-$SBT_VERSION.deb https://repo.scala-sbt.org/scalasbt/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

根据错误的外观,您尝试在 RUN 命令之前添加

最终结果将是

FROM openjdk:8 as build
ENV SBT_VERSION "1.5.8"
ENV APP_HOME /service
WORKDIR /app
# Install sbt
RUN \
  curl -L -o sbt-$SBT_VERSION.deb https://repo.scala-sbt.org/scalasbt/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

我认为问题出在使用根目录 / 作为工作目录。在 RUN ... 命令之前添加 WORKDIR /home 修复了 docker build ... 错误,我能够 docker run ... 成功。

docker build ...

docker build -f Dockerfile.so -t 70625015:latest .   
[+] Building 69.4s (7/7) FINISHED                                                                                             
 => [internal] load build definition from Dockerfile.so                                                                  0.0s
 => => transferring dockerfile: 387B                                                                                     0.0s
 => [internal] load .dockerignore                                                                                        0.0s
 => => transferring context: 2B                                                                                          0.0s
 => [internal] load metadata for docker.io/library/openjdk:8                                                             0.0s
 => CACHED [1/3] FROM docker.io/library/openjdk:8                                                                        0.0s
 => [2/3] WORKDIR /home                                                                                                  0.0s
 => [3/3] RUN   curl -L -o sbt-1.5.8.deb https://repo.scala-sbt.org/scalasbt/debian/sbt-1.5.8.deb &&   dpkg -i sbt-1.5  68.3s
 => exporting to image                                                                                                   0.9s 
 => => exporting layers                                                                                                  0.9s 
 => => writing image sha256:99e90196e9a6b2d768adf4e6a01883785847758a5f136f4a858a636e60b77819                             0.0s 
 => => naming to docker.io/library/70625015:latest                                                                       0.0s 

docker run .... 启动到 sbt 控制台。

(:|✔)$ docker run -it 70625015:latest
root@3a1084220dc9:/home#