web-dev-qa-db-ja.com

Docker内の起動時にSpring-bootアプリケーションが起動しない

Dockerコンテナ内で単純なSpring-Bootアプリケーションを実行しています。起動時に、Java -jar MY_JAR.jarまたはmvn spring-boot:runのどちらで開始した場合でも、アプリケーションは常に次の時点でハングします。

2014-12-22 23:26:58.957  INFO 1 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]

これが問題です。これは、コンテナー内で実行されている場合でも、DigitalOcean(1CPU、1GB MEM)のUbuntu14.04ボックスでのみ再現できます。私のローカルマシン(Mac)では、すべてが正常に実行されます。

Dockerfile:

FROM Java:8
ADD target/MY_SERVICE-1.0-SNAPSHOT.jar /data/svc.jar
EXPOSE 8080
CMD ["Java", "-jar", "/data/svc.jar"]

私が試したこと

  • JVMにより多くのメモリを提供します(マシン全体の75%)
  • 提案どおりにhavegedライブラリをインストールする ここ
  • 他のすべてのバージョンのJava私は手に入れることができました

助言がありますか?

助けてくれてありがとう。

ログ全体(-debugで始まる):

[Text Art Omitted]

 :: Spring Boot ::       (v1.1.10.RELEASE)

2014-12-22 19:22:58.375  INFO 20816 --- [           main] com.spectrom.uploadService.Main          : Starting Main on spectrom-services with PID 20816 (/root/spectrom-upload-service/target/upload-service-1.0-SNAPSHOT.jar started by root in /root/spectrom-upload-service)
2014-12-22 19:22:58.392 DEBUG 20816 --- [           main] o.s.boot.SpringApplication               : Loading source class com.spectrom.uploadService.Main
2014-12-22 19:22:58.671 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Skipped config file 'file:./config/application.yaml' resource not found
2014-12-22 19:22:58.673 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Skipped config file 'file:./config/application.properties' resource not found
2014-12-22 19:22:58.674 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Skipped config file 'file:./config/application.yml' resource not found
2014-12-22 19:22:58.675 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Skipped config file 'file:./application.yaml' resource not found
2014-12-22 19:22:58.675 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Skipped config file 'file:./application.properties' resource not found
2014-12-22 19:22:58.676 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Skipped config file 'file:./application.yml' resource not found
2014-12-22 19:22:58.677 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Skipped config file 'classpath:/config/application.yaml' resource not found
2014-12-22 19:22:58.678 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Skipped config file 'classpath:/config/application.properties' resource not found
2014-12-22 19:22:58.679 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Skipped config file 'classpath:/config/application.yml' resource not found
2014-12-22 19:22:58.679 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Skipped config file 'classpath:/application.yaml' resource not found
2014-12-22 19:22:58.680 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Loaded config file 'classpath:/application.properties'
2014-12-22 19:22:58.681 DEBUG 20816 --- [           main] o.s.b.c.c.ConfigFileApplicationListener  : Skipped config file 'classpath:/application.yml' resource not found
2014-12-22 19:22:58.693  INFO 20816 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@ddd51a7: startup date [Mon Dec 22 19:22:58 EST 2014]; root of context hierarchy
2014-12-22 19:22:58.708 DEBUG 20816 --- [           main] ationConfigEmbeddedWebApplicationContext : Bean factory for org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@ddd51a7: org.springframework.beans.factory.support.DefaultListableBeanFactory@47649f10: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,main]; root of factory hierarchy
2014-12-22 19:23:00.964  INFO 20816 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2014-12-22 19:23:02.480 DEBUG 20816 --- [           main] ationConfigEmbeddedWebApplicationContext : Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@177df6c1]
2014-12-22 19:23:02.481 DEBUG 20816 --- [           main] ationConfigEmbeddedWebApplicationContext : Using ApplicationEventMulticaster [org.springframework.context.event.SimpleApplicationEventMulticaster@4ed304f3]
2014-12-22 19:23:03.647 DEBUG 20816 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Code archive: /root/spectrom-upload-service/target/upload-service-1.0-SNAPSHOT.jar
2014-12-22 19:23:03.648 DEBUG 20816 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Code archive: /root/spectrom-upload-service/target/upload-service-1.0-SNAPSHOT.jar
2014-12-22 19:23:03.648 DEBUG 20816 --- [           main] .t.TomcatEmbeddedServletContainerFactory : None of the document roots [src/main/webapp, public, static] point to a directory and will be ignored.
2014-12-22 19:23:03.691  INFO 20816 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080
2014-12-22 19:23:04.855  INFO 20816 --- [           main] o.Apache.catalina.core.StandardService   : Starting service Tomcat
2014-12-22 19:23:04.856  INFO 20816 --- [           main] org.Apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.57
2014-12-22 19:23:05.008  INFO 20816 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2014-12-22 19:23:05.009  INFO 20816 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 6326 ms
2014-12-22 19:23:06.928  INFO 20816 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2014-12-22 19:23:06.933  INFO 20816 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]

^ cの後:

^C2014-12-22 19:24:28.771  INFO 20816 --- [       Thread-2] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@ddd51a7: startup date [Mon Dec 22 19:22:58 EST 2014]; root of context hierarchy
2014-12-22 19:24:28.815  WARN 20816 --- [       Thread-2] ationConfigEmbeddedWebApplicationContext : Exception thrown from LifecycleProcessor on context close

Java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@ddd51a7: startup date [Mon Dec 22 19:22:58 EST 2014]; root of context hierarchy
    at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.Java:359)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.Java:890)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.Java:141)
    at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.Java:811)

ハング中のスレッドダンプ:

2014-12-23 01:09:58
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode):

"localhost-startStop-1" #13 daemon prio=5 os_prio=0 tid=0x00007f56c431a800 nid=0x12 runnable [0x00007f56e0bec000]
   Java.lang.Thread.State: RUNNABLE
    at Java.io.FileInputStream.readBytes(Native Method)
    at Java.io.FileInputStream.read(FileInputStream.Java:246)
    at Sun.security.provider.SeedGenerator$URLSeedGenerator.getSeedBytes(SeedGenerator.Java:539)
    at Sun.security.provider.SeedGenerator.generateSeed(SeedGenerator.Java:144)
    at Sun.security.provider.SecureRandom$SeederHolder.<clinit>(SecureRandom.Java:203)
    at Sun.security.provider.SecureRandom.engineNextBytes(SecureRandom.Java:221)
    - locked <0x00000000f10478f8> (a Sun.security.provider.SecureRandom)
    at Java.security.SecureRandom.nextBytes(SecureRandom.Java:457)
    - locked <0x00000000f1047c18> (a Java.security.SecureRandom)
    at Java.security.SecureRandom.next(SecureRandom.Java:480)
    at Java.util.Random.nextInt(Random.Java:329)
    at org.Apache.catalina.util.SessionIdGenerator.createSecureRandom(SessionIdGenerator.Java:246)
    at org.Apache.catalina.util.SessionIdGenerator.getRandomBytes(SessionIdGenerator.Java:183)
    at org.Apache.catalina.util.SessionIdGenerator.generateSessionId(SessionIdGenerator.Java:153)
    at org.Apache.catalina.session.ManagerBase.startInternal(ManagerBase.Java:573)
    at org.Apache.catalina.session.StandardManager.startInternal(StandardManager.Java:485)
    - locked <0x00000000f0fa82e0> (a org.Apache.catalina.session.StandardManager)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    - locked <0x00000000f0fa82e0> (a org.Apache.catalina.session.StandardManager)
    at org.Apache.catalina.core.StandardContext.startInternal(StandardContext.Java:5501)
    - locked <0x00000000f68e5d68> (a org.springframework.boot.context.embedded.Tomcat.TomcatEmbeddedContext)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    - locked <0x00000000f68e5d68> (a org.springframework.boot.context.embedded.Tomcat.TomcatEmbeddedContext)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1575)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1565)
    at Java.util.concurrent.FutureTask.run(FutureTask.Java:266)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1142)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:617)
    at Java.lang.Thread.run(Thread.Java:745)

"Tomcat-startStop-1" #12 daemon prio=5 os_prio=0 tid=0x00007f56c8405000 nid=0x11 waiting on condition [0x00007f56f4103000]
   Java.lang.Thread.State: WAITING (parking)
    at Sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000000f69aa980> (a Java.util.concurrent.FutureTask)
    at Java.util.concurrent.locks.LockSupport.park(LockSupport.Java:175)
    at Java.util.concurrent.FutureTask.awaitDone(FutureTask.Java:429)
    at Java.util.concurrent.FutureTask.get(FutureTask.Java:191)
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:1123)
    - locked <0x00000000f68505c0> (a org.Apache.catalina.core.StandardHost)
    at org.Apache.catalina.core.StandardHost.startInternal(StandardHost.Java:816)
    - locked <0x00000000f68505c0> (a org.Apache.catalina.core.StandardHost)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    - locked <0x00000000f68505c0> (a org.Apache.catalina.core.StandardHost)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1575)
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1565)
    at Java.util.concurrent.FutureTask.run(FutureTask.Java:266)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1142)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:617)
    at Java.lang.Thread.run(Thread.Java:745)

"DestroyJavaVM" #10 prio=5 os_prio=0 tid=0x00007f56f0009800 nid=0x7 waiting on condition [0x0000000000000000]
   Java.lang.Thread.State: RUNNABLE

"main" #9 prio=5 os_prio=0 tid=0x00007f56f0159800 nid=0x10 waiting on condition [0x00007f56f4cf0000]
   Java.lang.Thread.State: WAITING (parking)
    at Sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000000f69aac08> (a Java.util.concurrent.FutureTask)
    at Java.util.concurrent.locks.LockSupport.park(LockSupport.Java:175)
    at Java.util.concurrent.FutureTask.awaitDone(FutureTask.Java:429)
    at Java.util.concurrent.FutureTask.get(FutureTask.Java:191)
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:1123)
    - locked <0x00000000f68d1648> (a org.Apache.catalina.core.StandardEngine)
    at org.Apache.catalina.core.StandardEngine.startInternal(StandardEngine.Java:300)
    - locked <0x00000000f68d1648> (a org.Apache.catalina.core.StandardEngine)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    - locked <0x00000000f68d1648> (a org.Apache.catalina.core.StandardEngine)
    at org.Apache.catalina.core.StandardService.startInternal(StandardService.Java:443)
    - locked <0x00000000f68d1648> (a org.Apache.catalina.core.StandardEngine)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    - locked <0x00000000f6850418> (a org.Apache.catalina.core.StandardService)
    at org.Apache.catalina.core.StandardServer.startInternal(StandardServer.Java:739)
    - locked <0x00000000f6850590> (a [Lorg.Apache.catalina.Service;)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    - locked <0x00000000f683f5d8> (a org.Apache.catalina.core.StandardServer)
    at org.Apache.catalina.startup.Tomcat.start(Tomcat.Java:341)
    at org.springframework.boot.context.embedded.Tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.Java:85)
    - locked <0x00000000f68c4660> (a org.springframework.boot.context.embedded.Tomcat.TomcatEmbeddedServletContainer)
    at org.springframework.boot.context.embedded.Tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.Java:74)
    at org.springframework.boot.context.embedded.Tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.Java:377)
    at org.springframework.boot.context.embedded.Tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.Java:153)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.Java:148)
    - locked <0x00000000f5dd9708> (a org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.Java:121)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:476)
    - locked <0x00000000f5de2550> (a Java.lang.Object)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.Java:109)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:691)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:320)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:952)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:941)
    at com.spectrom.uploadService.Main.main(Main.Java:17)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:483)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.Java:53)
    at Java.lang.Thread.run(Thread.Java:745)

"Service Thread" #7 daemon prio=9 os_prio=0 tid=0x00007f56f00cd000 nid=0xe runnable [0x0000000000000000]
   Java.lang.Thread.State: RUNNABLE

"C1 CompilerThread1" #6 daemon prio=9 os_prio=0 tid=0x00007f56f00ca000 nid=0xd waiting on condition [0x0000000000000000]
   Java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #5 daemon prio=9 os_prio=0 tid=0x00007f56f00c8000 nid=0xc waiting on condition [0x0000000000000000]
   Java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" #4 daemon prio=9 os_prio=0 tid=0x00007f56f00c6000 nid=0xb waiting on condition [0x0000000000000000]
   Java.lang.Thread.State: RUNNABLE

"Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007f56f009a000 nid=0xa in Object.wait() [0x00007f56f5500000]
   Java.lang.Thread.State: WAITING (on object monitor)
    at Java.lang.Object.wait(Native Method)
    - waiting on <0x00000000f5bb8068> (a Java.lang.ref.ReferenceQueue$Lock)
    at Java.lang.ref.ReferenceQueue.remove(ReferenceQueue.Java:142)
    - locked <0x00000000f5bb8068> (a Java.lang.ref.ReferenceQueue$Lock)
    at Java.lang.ref.ReferenceQueue.remove(ReferenceQueue.Java:158)
    at Java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.Java:209)

"Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007f56f0097800 nid=0x9 in Object.wait() [0x00007f56f5601000]
   Java.lang.Thread.State: WAITING (on object monitor)
    at Java.lang.Object.wait(Native Method)
    - waiting on <0x00000000f5bb8220> (a Java.lang.ref.Reference$Lock)
    at Java.lang.Object.wait(Object.Java:502)
    at Java.lang.ref.Reference$ReferenceHandler.run(Reference.Java:157)
    - locked <0x00000000f5bb8220> (a Java.lang.ref.Reference$Lock)

"VM Thread" os_prio=0 tid=0x00007f56f0090800 nid=0x8 runnable

"VM Periodic Task Thread" os_prio=0 tid=0x00007f56f00dc800 nid=0xf waiting on condition

JNI global references: 29

Heap
 def new generation   total 13696K, used 12232K [0x00000000f0600000, 0x00000000f14d0000, 0x00000000f5950000)
  eden space 12224K,  88% used [0x00000000f0600000, 0x00000000f1082050, 0x00000000f11f0000)
  from space 1472K, 100% used [0x00000000f11f0000, 0x00000000f1360000, 0x00000000f1360000)
  to   space 1472K,   0% used [0x00000000f1360000, 0x00000000f1360000, 0x00000000f14d0000)
 tenured generation   total 30240K, used 20916K [0x00000000f5950000, 0x00000000f76d8000, 0x0000000100000000)
   the space 30240K,  69% used [0x00000000f5950000, 0x00000000f6dbd1b0, 0x00000000f6dbd200, 0x00000000f76d8000)
 Metaspace       used 23431K, capacity 23620K, committed 23728K, reserved 1071104K
  class space    used 2909K, capacity 2974K, committed 2992K, reserved 1048576K
17
Scott

とった!ホストにhavegedをインストールすると、プロセスはすぐに進み、Springは正常に起動しました。 dockerがホスト上のhavegedとどのように相互作用するかについてもう少し調査したら、さらに投稿します。

要約すると、ホストで発行された次のコマンドで問題が修正されます。

apt-get install haveged -y

誰かがこれを詳細に理解しているなら、気軽に投稿してください!

現時点で私が理解していないのは、ホストマシンに追加のコードが必要であり、すべてがDockerコンテナー内で分離されていない理由です。

31
Scott

後でここに来るかもしれない人のために。最も簡単な解決策は、Dockerfileを変更し、次のようにエントリポイントを設定することだと思います。

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

30秒から15分の間(またはそれ以上かもしれませんが、殺された)のどこかにアプリがぶら下がっている経験があります。

詳細を共有する他の投稿から:

これがないと、Javaは/dev/randomを使用してSecureRandomクラスをシードし、Javaコードが予期せずブロックされる可能性があります。

または、$Java_HOME/jre/lib/security/Java.security構成ファイルに次の行を追加します

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

脚注:上記の例では、Javaをだましてファイル名を受け入れるようにするには、余分な/./などの奇妙なファイル名が必要です。/dev/urandomを使用するだけの場合、Javaは、あなたが本当にそれを意味していないと判断し、あなたが書いたものを/ dev/randomに置き換えます。狂気!

17
Jenya G