On this page

Build a Scala Native app in Alpine 🔗

Use a multi-stage Docker build when you want Deder to run in Alpine and ship a small image containing only the Scala Native executable.

  1. Install Alpine's clang and GCC packages in the build stage:

    FROM eclipse-temurin:21-jdk-alpine AS build
    RUN apk add --no-cache clang gcc curl
    

    Temurin provides the JDK 21 required by Deder's server. gcc supplies crtbeginS.o, libgcc, and libgcc_s, which Scala Native's link step requires on Alpine.

  2. Run Deder from deder-client.jar:

    RUN java -jar /opt/deder/deder-client.jar exec \
          --log-level warning \
          --no-color \
          -t nativeLink \
          -m app
    

    The released native Deder client is glibc-linked, so use the JAR client in the Alpine build stage. Deder reads the server version from the active amends URL in deder.pkl, then downloads the matching server and test-runner artifacts.

  3. Copy the linked executable into the runtime stage:

    FROM alpine:3.23
    COPY --from=build /src/.deder/out/app/nativeLink/app /usr/local/bin/app
    ENTRYPOINT ["app"]
    

The Scala Native example Dockerfile combines these stages for the cli module:

cd examples/scalanative
docker build -t deder-scalanative-example .
docker run --rm deder-scalanative-example

The example uses the version from its deder.pkl config URL by default. To override both the client and server versions, set DEDER_VERSION. The Dockerfile then writes that version to .deder/server.properties:

docker build \
  --build-arg DEDER_VERSION=v0.22.2 \
  -t deder-scalanative-example .

The final image in this example is approximately 15 MB. If your application uses additional native libraries, install those libraries in the runtime stage as well.

⬅️ Plugins OTEL tracing/logging/metrics ➡️