【问题标题】:Docker, sbt - cannot install sbt with centos docker imageDocker, sbt - 无法使用 centos docker 映像安装 sbt
【发布时间】:2020-05-16 10:39:26
【问题描述】:

我想在我的docker 图像中添加 sbt。我基于centos:centos8 图像创建了Dockerfile

FROM centos:centos8
ENV SCALA_VERSION 2.13.1
ENV SBT_VERSION 0.13.18

RUN  yum install -y epel-release
RUN  yum update -y && yum install -y wget

RUN wget -O /usr/local/bin/sbt-launch.jar http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/$SBT_VERSION/sbt-launch.jar

WORKDIR /root
EXPOSE 8080

RUN sbt compile
CMD sbt run

我还需要在这里安装sbt,但是当我运行这个脚本时出现错误:

Step 10/11 : RUN sbt compile
 ---> Running in 0aadcd774ba0
/bin/sh: sbt: command not found

我不明白为什么找不到sbt。这是实现我需要的好方法还是我应该尝试其他方法?但我需要使用centos

编辑:

在下面的答案的帮助下,它终于可以工作了。工作脚本如下所示:

FROM centos:centos8
ENV SBT_VERSION 0.13.17

RUN yum install -y java-11-openjdk && \
    yum install -y epel-release && \
    yum update -y && yum install -y wget && \
    wget http://dl.bintray.com/sbt/rpm/sbt-$SBT_VERSION.rpm && \
    yum install -y sbt-$SBT_VERSION.rpm

WORKDIR /root
EXPOSE 8080

RUN sbt compile
CMD sbt run

【问题讨论】:

  • 我认为 Dockerfile 中的任何内容都不会在系统路径中创建一个名为 sbt 的可执行文件。仅仅下载一个 jar 文件是不行的。

标签: docker centos sbt dockerfile


【解决方案1】:

您需要在您的Dockerfile 中安装sbt。这是一个例子:

FROM centos:centos8
ENV SCALA_VERSION 2.13.1
ENV SBT_VERSION 0.13.17

RUN yum install -y epel-release
RUN yum update -y && yum install -y wget

# INSTALL JAVA
RUN yum install -y java-11-openjdk

# INSTALL SBT
RUN wget http://dl.bintray.com/sbt/rpm/sbt-${SBT_VERSION}.rpm
RUN yum install -y sbt-${SBT_VERSION}.rpm

RUN wget -O /usr/local/bin/sbt-launch.jar http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/$SBT_VERSION/sbt-launch.jar

WORKDIR /root
EXPOSE 8080

RUN sbt compile
CMD sbt run

注意:我没有在 env 变量中看到您的版本 (0.13.18),所以我将其更改为 0.13.17。

【讨论】:

  • 它对你有用吗?我得到了The command '/bin/sh -c yum install sbt-${SBT_VERSION}.rpm' returned a non-zero code: 1
  • 忘记了-y。我会更新线路。我实际上没有对其进行测试,但您遇到的问题是您的图像中不存在sbt
  • 现在好多了,但我得到了Step 10/11 : RUN sbt compile ---> Running in 66ec059d2144 /usr/share/sbt/bin/sbt-launch-lib.bash: line 262: java: command not found Copying runtime jar. mkdir: cannot create directory '': No such file or directory /usr/share/sbt/bin/sbt-launch-lib.bash: line 74: java: command not found /usr/share/sbt/bin/sbt-launch-lib.bash: line 74: java: command not found,所以可能我也需要安装java
  • 是的,我也得到了古玩并运行了它。同样的答案,您需要安装应用程序的所有依赖项。你可能会使用RUN yum install -y java-11-openjdk
  • 终于成功了。谢谢你。我在第一篇文章中添加解决方案
【解决方案2】:

我遇到了 bintray.com 随机返回 403 的问题。我假设它可能是某种流量限制。在本地添加 rpm 文件。

COPY sbt-0.13.18.rpm /
RUN yum install -y sbt-0.13.18.rpm

【讨论】:

    猜你喜欢
    • 2015-08-03
    • 1970-01-01
    • 2020-08-14
    • 1970-01-01
    • 2014-08-29
    • 2012-01-18
    • 2018-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多