sbt-native-packager: Scala App on Alpine Docker Image fails with permission denied
run the sbt task docker:stage
. Then analyze the output created in the folder target/docker/stage
.
In my case the Dockerfile
contains the following:
FROM openjdk:11-jre-slim as stage0WORKDIR /opt/dockerCOPY opt /optUSER rootRUN ["chmod", "-R", "u=rX,g=rX", "/opt/docker"]RUN ["chmod", "u+x,g+x", "/opt/docker/bin/sample"]FROM openjdk:11-jre-slimLABEL MAINTAINER="your name"USER rootRUN id -u demiourgos728 2> /dev/null || useradd --system --create-home --uid 1001 --gid 0 demiourgos728WORKDIR /opt/dockerCOPY --from=stage0 --chown=demiourgos728:root /opt/docker /opt/dockerEXPOSE 9000USER 1001ENTRYPOINT ["/opt/docker/bin/sample"]CMD []
I had the problem that the PID file could not be created. I think in your case it will be something similar. There is no magic involved here.
The folder /opt/docker
does not have write permissions by default. As the documentation states, you could add the following line to your build.sbt
:
dockerAdditionalPermissions += (DockerChmodType.UserGroupWriteExecute, "/opt/docker")
which will add an additional line:
RUN ["chmod", "u=rwX,g=rwX", "/opt/docker"]
to the stage0
container. See nativer packager docs.
Alternatively, disable the PID file by passing a parameter to the JVM:
bashScriptExtraDefines ++= Seq( "addJava '-Dpidfile.path=/dev/null'" )
to your build.sbt. Play Production configuration Docs