OCI 错误“/opt/docker/bin/my_job”:没有这样的文件或目录使用 sbt docker:publishLocal
OCI error "/opt/docker/bin/my_job" : no such file or directory using sbt docker:publishLocal
如果您使用 sbt docker:publishLocal
从您的 scala 项目构建一个 docker 图像,您将看到打印出以下行:
[info] Packaging /home/user123/myUser/repos/my_job/target/scala-2.12/app_internal_2.12-0.1.jar ...
[info] Done packaging.
[info] Sending build context to Docker daemon 129.7MB
[info] Step 1/7 : FROM openjdk:11-jre
[info] ---> 8c8b7f0ab84c
[info] Step 2/7 : LABEL MAINTAINER="no_name@my.org"
[info] ---> Using cache
[info] ---> d5caf9a92999
[info] Step 3/7 : WORKDIR /opt/docker
[info] ---> Using cache
[info] ---> d887eeb10e8e
[info] Step 4/7 : ADD --chown=root:root opt /opt
[info] ---> 1b43a84a5e32
[info] Step 5/7 : USER root
[info] ---> Running in 282c7f7de8ad
[info] Removing intermediate container 282c7f7de8ad
[info] ---> 11fed4892683
[info] Step 6/7 : ENTRYPOINT ["/opt/docker/bin/my_job"]
[info] ---> Running in 1d297dd1e960
[info] Removing intermediate container 1d297dd1e960
[info] ---> 1923a8df3fcf
[info] Step 7/7 : CMD []
[info] ---> Running in 3d9f7a4a262b
[info] Removing intermediate container 3d9f7a4a262b
[info] ---> d67ed46fd3fe
[info] Successfully built d67ed46fd3fe
[info] Successfully tagged docker_app_internal:0.1
[info] Built image docker_app_internal with tags [0.1]
[success] Total time: 25 s, completed Mar 27, 2019 10:23:35 AM
您可能会对错误感到困惑。为什么:
这有效:
docker run -it --entrypoint=/bin/bash docker_app_internal:0.1 -i
无效:
docker run docker_app_internal:0.1
感谢@Muki 创建了这个有用的项目。
参考:https://github.com/sbt/sbt-native-packager
如果您的项目根文件夹不同于 MainClass 名称,那么您使用 sbt docker:publishLocal
的 entrypoint
将变为 /your/linuxpath/bin/rootFolder
。但是,在 docker 图像中创建的实际文件是 /your/linuxpath/bin/main-class
(如果您的主要 class 名称是 MainClass)
要解决此问题,请在 build.sbt
中明确提及入口点,如下所示:
dockerEntrypoint := Seq("/opt/docker/bin/main-class")
如果您使用 sbt docker:publishLocal
从您的 scala 项目构建一个 docker 图像,您将看到打印出以下行:
[info] Packaging /home/user123/myUser/repos/my_job/target/scala-2.12/app_internal_2.12-0.1.jar ...
[info] Done packaging.
[info] Sending build context to Docker daemon 129.7MB
[info] Step 1/7 : FROM openjdk:11-jre
[info] ---> 8c8b7f0ab84c
[info] Step 2/7 : LABEL MAINTAINER="no_name@my.org"
[info] ---> Using cache
[info] ---> d5caf9a92999
[info] Step 3/7 : WORKDIR /opt/docker
[info] ---> Using cache
[info] ---> d887eeb10e8e
[info] Step 4/7 : ADD --chown=root:root opt /opt
[info] ---> 1b43a84a5e32
[info] Step 5/7 : USER root
[info] ---> Running in 282c7f7de8ad
[info] Removing intermediate container 282c7f7de8ad
[info] ---> 11fed4892683
[info] Step 6/7 : ENTRYPOINT ["/opt/docker/bin/my_job"]
[info] ---> Running in 1d297dd1e960
[info] Removing intermediate container 1d297dd1e960
[info] ---> 1923a8df3fcf
[info] Step 7/7 : CMD []
[info] ---> Running in 3d9f7a4a262b
[info] Removing intermediate container 3d9f7a4a262b
[info] ---> d67ed46fd3fe
[info] Successfully built d67ed46fd3fe
[info] Successfully tagged docker_app_internal:0.1
[info] Built image docker_app_internal with tags [0.1]
[success] Total time: 25 s, completed Mar 27, 2019 10:23:35 AM
您可能会对错误感到困惑。为什么: 这有效:
docker run -it --entrypoint=/bin/bash docker_app_internal:0.1 -i
无效:
docker run docker_app_internal:0.1
感谢@Muki 创建了这个有用的项目。
参考:https://github.com/sbt/sbt-native-packager
如果您的项目根文件夹不同于 MainClass 名称,那么您使用 sbt docker:publishLocal
的 entrypoint
将变为 /your/linuxpath/bin/rootFolder
。但是,在 docker 图像中创建的实际文件是 /your/linuxpath/bin/main-class
(如果您的主要 class 名称是 MainClass)
要解决此问题,请在 build.sbt
中明确提及入口点,如下所示:
dockerEntrypoint := Seq("/opt/docker/bin/main-class")