sbt-native-packager
sbt-native-packager copied to clipboard
DockerPlugin doesn't work with multiple main classes by default
Expected behaviour
sbt Docker/publishLocal produces a runnable image or fails at build time in the presence of multiple main classes
Actual behaviour
The image fails startup
Information
- What sbt-native-packager are you using: 1.9.7
- What sbt version: 1.6.1
- What is your build system: sbt
- What package are you building docker
- What version has your build tool: ???
- What is your target system: macOS, also confirmed on Linux
Reproduction
- Make an sbt project using NP:
val root = project
.in(file("."))
.enablePlugins(JavaAppPackaging)
.enablePlugins(DockerPlugin)
- Add multiple main classes
object Foo extends App
object Bar extends App
-
sbt Docker/publishLocal -
Try to run the generated image:
$ docker run --rm -it sha256:46c53661a82306d95dbd9e9db28fa7e98d7f5ae4553d5c0091f0f71dfdbb8c97
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/opt/docker/bin/root": stat /opt/docker/bin/root: no such file or directory: unknown.
Docker/dockerEntrypoint points to /opt/docker/bin/root, and setting it to a specific binary helps. Clearly the names are set by a heuristic documented in the docs.
However, I don't think the Docker plugin's behavior is intuitive, because if you add a new main class to a working build you'll suddenly be unable to run the images.
Maybe Docker/stage should fail if there are many main classes and none of them is explicitly chosen (by Docker/mainClass or dockerEntrypoint, I'm not sure)?