web-dev-qa-db-ja.com

Spring BootアプリケーションでDockerイメージに接続できない

Dockerfile

FROM openjdk:8 
ADD target/docker-spring-boot.jar docker-spring-boot.jar
EXPOSE 8085
ENTRYPOINT ["Java","-jar","docker-spring-boot.jar"]

dockerをビルドするコマンド

docker build -f Dockerfile -t docker-spring-boot .

下のスプリングブートjarの場所。

target/docker-spring-boot.jar

dockerを実行するコマンド

docker run -p 8085:8085 docker-spring-boot

アプリケーションは、Dockerがなくても正常に動作します。 dockerでアプリケーションを実行できません。

エラー:

This site can’t be reached

docker実行ログ

 E:\micorservices_samples\docker-spring-boot\docker-springbootdocker run -p 8085 :8085 docker-spring-boot

   .   ____          _            __ _ _  /\\ / ___'_ __ _ _(_)_ __  __
 _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )   '  |____| .__|_| |_|_| |_\__, | / / / / 
 =========|_|==============|___/=/_/_/_/  :: Spring Boot ::        (v2.1.4.RELEASE)

 2019-04-07 18:29:47.944  INFO 1 --- [           main]
 c.r.d.DockerSpringbootAppl ication        : Starting
 DockerSpringbootApplication v0.0.1-SNAPSHOT on 352ac4d 12009 with PID
 1 (/docker-spring-boot.jar started by root in /) 2019-04-07
 18:29:47.970  INFO 1 --- [main] c.r.d.DockerSpringbootAppl
 ication        : No active profile set, falling back to default
 profiles: defaul t 2019-04-07 18:29:54.302  INFO 1 --- [          
 main] o.s.b.w.embedded.Tomcat.To mcatWebServer  : Tomcat initialized
 with port(s): 8085 (http) 2019-04-07 18:29:54.463  INFO 1 --- [       
 main] o.Apache.catalina.core.Sta ndardService   : Starting service
 [Tomcat] 2019-04-07 18:29:54.464  INFO 1 --- [           main]
 org.Apache.catalina.core.S tandardEngine  : Starting Servlet engine:
 [Apache Tomcat/9.0.17] 2019-04-07 18:29:54.854  INFO 1 --- [          
 main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring
 embedded WebApplicationContext 2019-04-07 18:29:54.855  INFO 1 --- [  
 main] o.s.web.context.ContextLoa der            : Root
 WebApplicationContext: initialization completed in 6539 ms 2019-04-07
 18:29:55.859  INFO 1 --- [main] o.s.s.concurrent.ThreadPoo
 lTaskExecutor  : Initializing ExecutorService
 'applicationTaskExecutor' 2019-04-07 18:29:56.691  INFO 1 --- [       
 main] o.s.b.w.embedded.Tomcat.To mcatWebServer  : Tomcat started on
 port(s): 8085 (http) with context path '' 2019-04-07 18:29:56.705 
 INFO 1 --- [main] c.r.d.DockerSpringbootAppl ication       
 : Started DockerSpringbootApplication in 10.902 seconds (JVM runn ing
 for 12.566)



 C:\Users\Mabeldocker logs -f 20026c6c7602

   .   ____          _            __ _ _  /\\ / ___'_ __ _ _(_)_ __  __
 _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )   '  |____| .__|_| |_|_| |_\__, | / / / / 
 =========|_|==============|___/=/_/_/_/  :: Spring Boot ::        (v2.1.4.RELEASE)

 2019-04-07 18:51:23.381  INFO 1 --- [           main]
 c.r.d.DockerSpringbootAppl ication        : Starting
 DockerSpringbootApplication v0.0.1-SNAPSHOT on 20026c6 c7602 with PID
 1 (/dsb.jar started by root in /) 2019-04-07 18:51:23.403  INFO 1 ---
 [           main] c.r.d.DockerSpringbootAppl ication        : No
 active profile set, falling back to default profiles: defaul t
 2019-04-07 18:51:29.434  INFO 1 --- [main]
 o.s.b.w.embedded.Tomcat.To mcatWebServer  : Tomcat initialized with
 port(s): 8085 (http) 2019-04-07 18:51:29.608  INFO 1 --- [          
 main] o.Apache.catalina.core.Sta ndardService   : Starting service
 [Tomcat] 2019-04-07 18:51:29.613  INFO 1 --- [           main]
 org.Apache.catalina.core.S tandardEngine  : Starting Servlet engine:
 [Apache Tomcat/9.0.17] 2019-04-07 18:51:30.012  INFO 1 --- [          
 main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring
 embedded WebApplicationContext 2019-04-07 18:51:30.014  INFO 1 --- [  
 main] o.s.web.context.ContextLoa der            : Root
 WebApplicationContext: initialization completed in 6275 ms 2019-04-07
 18:51:31.038  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoo
 lTaskExecutor  : Initializing ExecutorService
 'applicationTaskExecutor' 2019-04-07 18:51:31.879  INFO 1 --- [       
 main] o.s.b.w.embedded.Tomcat.To mcatWebServer  : Tomcat started on
 port(s): 8085 (http) with context path '' 2019-04-07 18:51:31.895 
 INFO 1 --- [           main] c.r.d.DockerSpringbootAppl ication       
 : Started DockerSpringbootApplication in 10.631 seconds (JVM runn ing
 for 12.241)

Githubリンク https://github.com/robert07ravikumar/spring-boot-docker

enter image description here

7

コードはどの[〜#〜] unix [〜#〜]マシンでも問題なく機能します。問題はWindowsバージョンのDockerネットワークに関連しています。デフォルトでdocker usebridgeネットワークが他に指定されていない場合は、WindowsでDockerネットワークは別の方法で機能し、リンクを確認できます- こちら 問題の詳細については。これは既知のバグですが、Dockerチームがいつか対処することを期待しています。

Elton Stoneman氏のブログでも、この問題についての詳しい説明が提供されています。次の link を参照してください。

0
ELavicount