question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docker Entrypoint does not consider mainClass option (and resulted script name)

See original GitHub issue

Expected behaviour

I have a project with multiple main classes and as state here: https://www.scala-sbt.org/sbt-native-packager/archetypes/java_app/index.html#usage I use

mainClass in(Compile, run) := Option("com.<redacted>.Boot")

The scripts in bin result with boot name which I think is to be expected.

Building the docker image for the project I expect the image to start properly.

Actual behaviour

The Entrypoint in the image is wrong, using project name and not considering the given mainClass option.

From docker inspect

ENTRYPOINT [\"/opt/microservice/bin/<project-name>\"]

Information

Plugin version: 1.7.0 SBT: 1.3.10 Built on Linux

Related options:

val dockerSettings = Seq(
  defaultLinuxInstallLocation in Docker := "/opt/microservice",
  dockerRepository in Docker := Some("<docker-registry>"),
  dockerExposedPorts in Docker := Seq(8080),
  // Ignore this, we need to run as root for now
  daemonUser in Docker := "root",
  daemonUserUid in Docker := None,
  version in Docker := version.value
)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lebenitzacommented, May 6, 2020

Thanks for your help!

1reaction
muuki88commented, May 6, 2020

Thanks for your patience @MihaiAnei 😅 Of course that’s the issue 🤦

I found the root cause. It’s, as quite a few times, a scoping issue. So the fix ist

// too narrow scope
Comile / run / mainClass := Some("...")

// just about right scope
Compile / mainClass := Some("....") 

the mainClass in (Compile,run) (I used the new syntax in the example above) isn’t used for setting the executableScriptName . So it falls back to the default behaviour.

The default behaviour, generating a script per class, doesn’t work very well with the docker plugin. However I’m fine with that as a docker image ideally as one entry point. IMHO that’s the point of having containers 😜 If you have multiple main classes, then setting the “default” one should be fine.

Thanks again for your help 😗

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot run script.sh with ENTRYPOINT Docker - Stack Overflow
When I run the container as mentioned above, I get the following error: : not foundta/script.sh: 2: /usr/src/data/script.sh: 's ...
Read more >
A Start to Finish Guide to Docker with Java - Stackify
Read an extensive, start to finish guide to building, managing and running a containerized Java Spring Boot application.
Read more >
Topical Guide | Spring Boot Docker
This is a guide for developers of Spring Boot applications, and containers are not always a good abstraction for developers. They force you...
Read more >
Run a Java application in a Docker container | IntelliJ IDEA ...
In the New Project dialog, select New Project and name the project DockerHelloJava . New Java project. Create the main Java class file...
Read more >
Demystifying ENTRYPOINT and CMD in Docker - Amazon AWS
Specifying CMD in a Dockerfile merely creates a default value: if we pass non-option arguments to docker run , they will override the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found