Spring-boot application won't boot at startup inside docker

后端 未结 2 1827
一生所求
一生所求 2020-12-23 12:17

I am running a simple spring-boot application inside a docker container. At startup whether started with java -jar MY_JAR.jar or mvn spring-boot:run

相关标签:
2条回答
  • 2020-12-23 13:03

    Got it! Once I installed haveged on the host, the process immediately moved forward, and spring booted fine. I will post more once I do a bit more research into how docker interacts with haveged on the host.

    In summary the following command issued on the host will fix the the issue:

    apt-get install haveged -y
    

    If anyone has a detailed understanding of this, feel free to post!

    The thing that I don't understand at the moment, is why the host machine needed extra code, and everything wasn't isolated within the docker container.

    0 讨论(0)
  • 2020-12-23 13:19

    For those who might come here later. I think easiest solution is to modify Dockerfile and have entry point as follows:

    ENTRYPOINT ["java", **"-Djava.security.egd=file:/dev/./urandom"**,"-jar","app.jar"]
    

    Had experience with apps hanging anywhere between 30 seconds and 15 minutes (or maybe more, but got killed).

    From the other post that shares details:

    Without this, Java uses /dev/random to seed its SecureRandom class, which can cause Java code to block unexpectedly.

    Alternatively, in the $JAVA_HOME/jre/lib/security/java.security configuration file, add the line

    securerandom.source=file:/dev/./urandom
    

    Footnote: In the above examples, you need the crazy-looking filename, e.g., the extra /./, to trick Java into accepting your filename. If you just use /dev/urandom, Java decides you didn't really mean it and replaces what you wrote with /dev/random. Craziness!

    0 讨论(0)
提交回复
热议问题