Home > OS >  Could not reach the docker container web application even it run successfully
Could not reach the docker container web application even it run successfully

Time:11-14

I wrote a simple backend application by spring boot and kotlin, here you can see the full settings https://github.com/lifeodyssey/demo

this bug performed as

  1. I can start and access the application by ./gradlew bootRun
  2. I can start and access the application by java -jar demo.jar
  3. But I could not access the application when I try to start it in a container, even I can see a successful log by docker logs containerID. The log is given below
2022-11-12 15:50:33.017  INFO 1 --- [           main] com.example.demo.DemoApplicationKt       : Starting DemoApplicationKt using Java 11.0.16 on eeb1dfe09e6a with PID 1 (/Demo-0.0.1.jar started by root in /)
2022-11-12 15:50:33.029  INFO 1 --- [           main] com.example.demo.DemoApplicationKt       : No active profile set, falling back to 1 default profile: "default"
2022-11-12 15:50:34.315  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2022-11-12 15:50:34.320  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2022-11-12 15:50:34.346  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 15 ms. Found 0 MongoDB repository interfaces.
2022-11-12 15:50:35.564  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8000 (http)
2022-11-12 15:50:35.595  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-11-12 15:50:35.596  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.68]
2022-11-12 15:50:35.787  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-11-12 15:50:35.788  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2628 ms
2022-11-12 15:50:38.155  WARN 1 --- [           main] o.s.b.a.m.MustacheAutoConfiguration      : Cannot find template location: classpath:/templates/ (please add some templates, check your Mustache configuration, or set spring.mustache.check-template-location=false)
2022-11-12 15:50:38.346  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8000 (http) with context path ''
2022-11-12 15:50:38.412  INFO 1 --- [           main] com.example.demo.DemoApplicationKt       : Started DemoApplicationKt in 6.588 seconds (JVM running for 7.745)

And here is the Dockerfile

FROM openjdk:11
COPY  /build/libs/demo-0.0.1-SNAPSHOT.jar Demo-0.0.1.jar
EXPOSE 8000
ENTRYPOINT ["java","-jar","/Demo-0.0.1.jar"]

Here is the commmand I used to build image and run container

docker build -t demo .
docker run -dp 8000:8000 demo:latest 

I could not find where is the problem. Can you help me with it ?

Update

Thanks for the comments below, here is what showed when I access localhost

This site can’t be reached localhost refused to connect.
Try:

Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED

I have tried change -dp 8000 to -d -p 8000, but nothing changed.

CodePudding user response:

Try to connect to it using 127.0.0.1:8000 instead of localhost:8000, maybe localhost is not resolving to 127.0.0.1.

If not try a different port and/or browser. Finally your firewall might be blocking your server so check that.

CodePudding user response:

I finally found the issue.

I installed two application two run my docker. One is colima, another is Docker Desktop.

I guess the problem is that docker do not know which one is the "localhost".

This problem fixed after I uninstall docker desktop and link docker to colima.

  • Related