Search code examples
scaladockersbtsbt-native-packager

OCI error "/opt/docker/bin/my_job" : no such file or directory using sbt docker:publishLocal


If you use sbt docker:publishLocal to build a docker image from your scala project, you will see the below lines printed out:

[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

You may get confused by the error. And why: THIS WORKS:

docker run -it --entrypoint=/bin/bash docker_app_internal:0.1  -i

Does not work:

docker run docker_app_internal:0.1

Thanks to @Muki for creating this helpful project.

Refer: https://github.com/sbt/sbt-native-packager


Solution

  • If you have the project root folder different from MainClass name, then your entrypoint using sbt docker:publishLocal becomes /your/linuxpath/bin/rootFolder. But, the actual file that gets created in the docker image is /your/linuxpath/bin/main-class (if your main class name is MainClass)

    To fix this, please explicitly mention the entrypoint in build.sbt as below:

    dockerEntrypoint := Seq("/opt/docker/bin/main-class")