skip to Main Content

I am using the sbt-native-packager plugin to generate a Docker image for a Scala project. The project requires a specific package libnetcdf.so to be installed on the image.

I am using the below configuration on my build.sbt

dockerCommands ++= Seq(
  ExecCmd("RUN","sudo","apt-get","update"),
  ExecCmd("RUN","sudo","apt-get","install","-y","libnetcdf-dev")
)

However when generating/building the image using sbt docker:publishLocal I get the below errors.

[error] #18 [mainstage 6/7] RUN ["sudo", "apt-get", "update"]
[error] #18 0.358 runc run failed: unable to start container process: exec: "sudo": executable file not found in $PATH
[error] #18 ERROR: process "sudo apt-get update" did not complete successfully: exit code: 1
[error] ------
[error]  > [mainstage 6/7] RUN ["sudo", "apt-get", "update"]:
[error] 0.358 runc run failed: unable to start container process: exec: "sudo": executable file not found in $PATH
[error] ------
[error] Dockerfile:24
[error] --------------------
[error]   22 |     ENTRYPOINT ["/opt/docker/bin/root"]
[error]   23 |     CMD []
[error]   24 | >>> RUN ["sudo", "apt-get", "update"]
[error]   25 |     RUN ["sudo", "apt-get", "install", "-y", "libnetcdf-dev"]
[error]   26 |
[error] --------------------
[error] ERROR: failed to solve: process "sudo apt-get update" did not complete successfully: exit code: 1

Cannot find the right way to install a dependency using the dockerCommands

Any help/pointers will be greatly appreciated.

2

Answers


  1. Remove sudo.

    ExecCmd("RUN","apt-get","update")
    

    It doesn’t exist in the image as the error says.

    And moreover you don’t need it because the build is likely done as root user, and only switched to a non-root user at the end. (Worth checking that though, I don’t know what the SBT plugin generates by default).

    Login or Signup to reply.
  2. You can use regular Cmd() objects as well as ExecCmd ones. In your build.sbt you can put this:

    import com.typesafe.sbt.packager.docker._
                  
    dockerCommands := Seq(
      Cmd("RUN", "apt-get", "update"),
      Cmd("RUN", "apt-get", "-y", "upgrade"),
      Cmd("RUN", "apt-get", "install","-y","libnetcdf-dev"),
      Cmd("USER", "1000"),               
      ExecCmd("ENTRYPOINT", "/app/docker/bin/my-app")
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search