You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu服务器构建Docker容器时遭遇sbt:not found错误求助

解决Docker构建时sbt: not found的问题

出现这个错误是因为你使用的openjdk:11镜像里没有安装sbt工具,无法执行sbt run命令。以下是几种解决方法:

方法一:在Dockerfile中手动安装sbt

修改Dockerfile,添加安装sbt的步骤:

FROM openjdk:11
WORKDIR /testimaje

# 安装sbt所需依赖及sbt本身
RUN apt-get update && apt-get install -y curl gnupg2 apt-transport-https && \
    echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | tee /etc/apt/sources.list.d/sbt.list && \
    curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | apt-key add - && \
    apt-get update && apt-get install -y sbt

COPY /play-samples-play-java-hello-world-tutorial .
EXPOSE 9000
CMD sbt run

方法二:使用预安装sbt的基础镜像

直接选用官方的sbt镜像,已包含对应版本JDK和sbt,更简洁:

FROM sbt:1.8.2-openjdk-11
WORKDIR /testimaje
COPY /play-samples-play-java-hello-world-tutorial .
EXPOSE 9000
CMD sbt run

方法三:提前打包成可执行Jar(推荐生产环境使用)

先在本地项目目录执行sbt dist生成打包文件,再修改Dockerfile直接运行Jar:

FROM openjdk:11
WORKDIR /app

# 复制本地打包生成的zip文件(路径需根据实际打包结果调整)
COPY target/universal/play-samples-play-java-hello-world-tutorial-*.zip .
RUN unzip play-samples-play-java-hello-world-tutorial-*.zip && \
    rm play-samples-play-java-hello-world-tutorial-*.zip && \
    mv play-samples-play-java-hello-world-tutorial-* app-dist

EXPOSE 9000
CMD ["./app-dist/bin/play-samples-play-java-hello-world-tutorial"]

这种方式无需在镜像中安装sbt,镜像体积更小,运行效率更高。

内容的提问来源于stack exchange,提问作者kudretmeral

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 05:37:20