I am having an issue with my dockerized webapp. Essentially I have a docker-compose yaml file and when the file is ran, everything seems to boot up smoothly. I can see that the container is running using docker ps. I can see that it is listening to the correct ports, however when I try to connect via my browser, it refuses to connect.
My yaml file
version: '3'
services:
product-search-service:
build: ./product-search-app
ports:
- 8000:5000
product-shipping-service:
build: ./product-shipping-app
ports:
- 9000:5000
website-app:
build: ./web-app
ports:
- 127.0.0.1:8080:80
volumes:
- ./web-app/public-html:/usr/local/apache2/htdocs/
I am connecting via the web browser to 127.0.0.1:8080
The console logs
Starting webstore-services_product-shipping-service_1 ... done Recreating webstore-services_website-app_1 ... done Starting webstore-services_product-search-service_1 ... done Attaching to webstore-services_product-shipping-service_1, webstore-services_product-search-service_1, webstore-services_website-app_1
website-app_1 | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.18.0.4. Set the 'ServerName' directive globally to suppress this message
website-app_1 | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.18.0.4. Set the 'ServerName' directive globally to suppress this message
website-app_1 | [Fri Mar 13 11:09:16.255235 2020] [mpm_event:notice] [pid 1:tid 140304540900680] AH00489: Apache/2.4.41 (Unix) configured -- resuming normal operations
product-search-service_1 |
product-search-service_1 | . ____ _ __ _ _
product-search-service_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
product-search-service_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
product-search-service_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
product-search-service_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
product-search-service_1 | =========|_|==============|___/=/_/_/_/
product-search-service_1 | :: Spring Boot :: (v2.0.5.RELEASE)
product-shipping-service_1 |
product-shipping-service_1 | . ____ _ __ _ _
product-shipping-service_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
product-shipping-service_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
product-shipping-service_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
product-shipping-service_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
product-shipping-service_1 | =========|_|==============|___/=/_/_/_/
product-shipping-service_1 | :: Spring Boot :: (v2.0.5.RELEASE)
product-search-service_1 |
product-search-service_1 | 2020-03-13 11:09:25.557 INFO 1 --- [ main] product.App : Starting App v0.1.0 on 82a04050f513 with PID 1 (/app/product-search-service-0.1.0.jar started by root in /app)
product-shipping-service_1 |
product-shipping-service_1 | 2020-03-13 11:09:25.743 INFO 1 --- [ main] shipping.App : Starting App v0.1.0 on 21735f5ffb12 with PID 1 (/app/product-shipping-service-0.1.0.jar started by root in /app)
product-search-service_1 | 2020-03-13 11:09:25.607 INFO 1 --- [ main] product.App : No active profile set, falling back to default profiles: default
product-shipping-service_1 | 2020-03-13 11:09:25.800 INFO 1 --- [ main] shipping.App : No active profile set, falling back to default profiles: default
product-search-service_1 | 2020-03-13 11:09:26.461 INFO 1 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#3339ad8e: startup date [Fri Mar 13 11:09:26 GMT 2020]; root of context hierarchy
product-shipping-service_1 | 2020-03-13 11:09:26.606 INFO 1 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#3c679bde: startup date [Fri Mar 13 11:09:26 GMT 2020]; root of context hierarchy
product-search-service_1 | 2020-03-13 11:09:41.208 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 5000 (http)
product-search-service_1 | 2020-03-13 11:09:41.583 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
product-search-service_1 | 2020-03-13 11:09:41.584 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
product-shipping-service_1 | 2020-03-13 11:09:41.540 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 5000 (http)
product-shipping-service_1 | 2020-03-13 11:09:41.914 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
product-shipping-service_1 | 2020-03-13 11:09:41.923 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
product-search-service_1 | 2020-03-13 11:09:41.708 INFO 1 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64:/usr/lib/jvm/java-1.8-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
product-search-service_1 | 2020-03-13 11:09:42.613 INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
product-shipping-service_1 | 2020-03-13 11:09:42.043 INFO 1 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64:/usr/lib/jvm/java-1.8-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
product-shipping-service_1 | 2020-03-13 11:09:42.873 INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
product-search-service_1 | 2020-03-13 11:09:42.615 INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 16228 ms
product-search-service_1 | 2020-03-13 11:09:43.319 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
product-search-service_1 | 2020-03-13 11:09:43.355 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
product-search-service_1 | 2020-03-13 11:09:43.364 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
product-search-service_1 | 2020-03-13 11:09:43.370 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
product-shipping-service_1 | 2020-03-13 11:09:42.874 INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 16315 ms
product-shipping-service_1 | 2020-03-13 11:09:43.471 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
product-shipping-service_1 | 2020-03-13 11:09:43.505 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
product-shipping-service_1 | 2020-03-13 11:09:43.508 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
product-shipping-service_1 | 2020-03-13 11:09:43.517 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
product-search-service_1 | 2020-03-13 11:09:43.371 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
product-shipping-service_1 | 2020-03-13 11:09:43.521 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
product-search-service_1 | 2020-03-13 11:09:44.733 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
product-shipping-service_1 | 2020-03-13 11:09:44.846 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
product-search-service_1 | 2020-03-13 11:09:46.595 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#3339ad8e: startup date [Fri Mar 13 11:09:26 GMT 2020]; root of context hierarchy
product-shipping-service_1 | 2020-03-13 11:09:46.656 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#3c679bde: startup date [Fri Mar 13 11:09:26 GMT 2020]; root of context hierarchy
product-search-service_1 | 2020-03-13 11:09:47.356 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/product]}" onto public product.Product product.ProductController.product(java.lang.String)
product-search-service_1 | 2020-03-13 11:09:47.448 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
product-shipping-service_1 | 2020-03-13 11:09:47.426 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/shipping]}" onto public shipping.Shipping shipping.ShippingController.shipping(long)
product-shipping-service_1 | 2020-03-13 11:09:47.491 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
product-search-service_1 | 2020-03-13 11:09:47.451 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
product-search-service_1 | 2020-03-13 11:09:47.758 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
product-shipping-service_1 | 2020-03-13 11:09:47.495 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
product-shipping-service_1 | 2020-03-13 11:09:47.773 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
product-search-service_1 | 2020-03-13 11:09:47.763 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
product-shipping-service_1 | 2020-03-13 11:09:47.778 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
product-search-service_1 | 2020-03-13 11:09:49.191 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
product-shipping-service_1 | 2020-03-13 11:09:49.232 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
product-shipping-service_1 | 2020-03-13 11:09:49.633 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 5000 (http) with context path ''
product-search-service_1 | 2020-03-13 11:09:49.612 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 5000 (http) with context path ''
I would also like to note that I have been following this tutorial and I can confirm that all prior steps were completed correctly as I have done this multiple times now
https://cpit490.gitlab.io/labs/lab-8/
Are there any logging features I can enable to get a better look at whats happening when I try to connect to 127.0.0.1 ?
EDIT
Attaching screenshot of the error
EDIT 2
Dockerfile for the web-app
FROM httpd:2-alpine
EXPOSE 80
EXPOSE 443
Edit 3
I am using docker toolbox in case this makes any difference. I don't have win10 pro or enterprise so I had to use toolbox
So I have figured out the issue.
Because I am running Docker Toolbox on Win10 home, my docker is running from VirtualBox which has its own IP address. To connect to my webapp, I need to use VB's IP instead of my local host. Win10 home doesn't have a hypervisor so localhost is essentially locked out from me :(
Credit goes to Docker Toolbox - Localhost not working
It seems that you didn't map correctly container's ports with localhost.
Update your yaml file like below:
version: '3'
services:
product-search-service:
build: ./product-search-app
ports:
- 8000:80
- 8001:443
product-shipping-service:
build: ./product-shipping-app
ports:
- 9000:80
- 9001:443
website-app:
build: ./web-app
ports:
- 8080:80
- 8081:443
volumes:
- ./web-app/public-html:/usr/local/apache2/htdocs/
Now you can browse to
localhost:8080 or localhost:8081
Related
I have created a Spring Boot Application with Spring Initializr. I use Spring Data with MySQL JDBC Connection. I created an docker image with gradle bootBuildImage and start this docker image with docker run --rm -p 8080:80 buchschrank:0.0.1-SNAPSHOT. But startup needs about 2-3 seconds instead of milliseconds:
2021-11-09 16:03:32.238 INFO 1 --- [ main] o.s.nativex.NativeListener : This application is bootstrapped with code generated with Spring AOT
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.6)
2021-11-09 16:03:32.277 INFO 1 --- [ main] o.s.boot.SpringApplication : Starting application using Java 11.0.13 on 2b2e5a51334b with PID 1 (started by cnb in /workspace)
2021-11-09 16:03:32.277 INFO 1 --- [ main] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2021-11-09 16:03:32.326 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-11-09 16:03:32.329 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 2 ms. Found 1 JPA repository interfaces.
2021-11-09 16:03:32.388 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 80 (http)
2021-11-09 16:03:32.389 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-11-09 16:03:32.389 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.54]
2021-11-09 16:03:32.395 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-11-09 16:03:32.395 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 116 ms
2021-11-09 16:03:32.412 INFO 1 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-11-09 16:03:32.414 INFO 1 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.32.Final
2021-11-09 16:03:32.415 INFO 1 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-11-09 16:03:32.417 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-11-09 16:03:33.840 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-11-09 16:03:33.842 INFO 1 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2021-11-09 16:03:34.973 INFO 1 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-11-09 16:03:34.974 INFO 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-11-09 16:03:35.033 WARN 1 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-11-09 16:03:35.077 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 80 (http) with context path ''
2021-11-09 16:03:35.078 INFO 1 --- [ main] o.s.boot.SpringApplication : Started application in 2.852 seconds (JVM running for 2.854)
The sourcecode of my example application: https://github.com/lesestunden/buchschrank-backend
Any idea what is wrong with my application setup? Thanks a lot!
Reason was slow initial connection to database. With local running mysql database startup is around 200ms.
I try to connect spring app with postgresql.
When I run my app directly on server(not container), Connection success.
java -jar app.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.5)
2021-07-05 14:10:58.348 INFO 334534 --- [ main] com.studb.poemNote.PoemNoteApplication : Starting PoemNoteApplication v1 using Java 11.0.11 on ip-172-31-3-67 with PID 334534 (/home/ubuntu/poemnote/poemNote/target/poemNote-1.jar started by ubuntu in /home/ubuntu/poemnote/poemNote)
2021-07-05 14:10:58.355 INFO 334534 --- [ main] com.studb.poemNote.PoemNoteApplication : No active profile set, falling back to default profiles: default
2021-07-05 14:11:00.447 INFO 334534 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode.
2021-07-05 14:11:00.498 INFO 334534 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 46 ms. Found 0 JDBC repository interfaces.
2021-07-05 14:11:01.903 INFO 334534 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2021-07-05 14:11:01.936 INFO 334534 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-07-05 14:11:01.936 INFO 334534 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-07-05 14:11:02.095 INFO 334534 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-07-05 14:11:02.095 INFO 334534 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3595 ms
2021-07-05 14:11:02.945 INFO 334534 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-07-05 14:11:03.197 INFO 334534 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2021-07-05 14:11:04.497 INFO 334534 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-07-05 14:11:04.762 INFO 334534 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2021-07-05 14:11:05.241 INFO 334534 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9000 (http) with context path ''
2021-07-05 14:11:05.267 INFO 334534 --- [ main] com.studb.poemNote.PoemNoteApplication : Started PoemNoteApplication in 8.396 seconds (JVM running for 9.694)
^C2021-07-05 14:11:13.986 INFO 334534 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
But when i run container, connection fail like below
docker run -p port:port
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.5)
2021-07-05 14:12:37.130 INFO 1 --- [ main] com.studb.poemNote.PoemNoteApplication : Starting PoemNoteApplication v1 using Java 11.0.11 on de04c6a415a5 with PID 1 (/app/BOOT-INF/classes started by root in /app)
2021-07-05 14:12:37.139 INFO 1 --- [ main] com.studb.poemNote.PoemNoteApplication : No active profile set, falling back to default profiles: default
2021-07-05 14:12:38.997 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode.
2021-07-05 14:12:39.055 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 47 ms. Found 0 JDBC repository interfaces.
2021-07-05 14:12:40.351 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2021-07-05 14:12:40.383 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-07-05 14:12:40.383 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-07-05 14:12:40.516 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-07-05 14:12:40.516 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3260 ms
2021-07-05 14:12:41.248 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-07-05 14:12:52.405 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315) ~[postgresql-42.2.19.jar:42.2.19]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.2.19.jar:42.2.19]
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223) ~[postgresql-42.2.19.jar:42.2.19]
at org.postgresql.Driver.makeConnection(Driver.java:465) ~[postgresql-42.2.19.jar:42.2.19]
at org.postgresql.Driver.connect(Driver.java:264) ~[postgresql-42.2.19.jar:42.2.19]
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477) ~[HikariCP-3.4.5.jar:na]
It's my dockerfile
FROM adoptopenjdk:11-jre-hotspot as builder
WORKDIR app
ARG JAR_FILE=target/*jar
COPY ${JAR_FILE} app.jar
RUN java -Djarmode=layertools -jar app.jar extract
FROM adoptopenjdk:11-jre-hotspot
WORKDIR app
COPY --from=builder app/dependencies/ ./
COPY --from=builder app/spring-boot-loader/ ./
COPY --from=builder app/snapshot-dependencies/ ./
COPY --from=builder app/application/ ./
EXPOSE 9000
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
I can't understand why it does...
I try run container '--network host' but it's failed.
Postgresql running inside container on the same host
In case postgresql is also running inside a container of the same host, you need to make sure that they share the same network and that the containers can reach each other.
Check configured networks of the container:
docker inspect <container> -f "{{json .NetworkSettings.Networks }}"
Check if you can reach one container from the another:
docker exec -u 0 <container1> ping <container2> -c2
In case they are not on the same network, you need to create the network first and then connect the containers to it:
docker network create <network>
and
docker network connect <network> <container>
Postgresql running directly on the host
In case postgresql is running directly on the host where your docker container is running, you need to make sure that you can reach the host system from your container. Try to add the following command when you start the container
--add-host=host.docker.internal:host-gateway
Useful Links:
How to access host port from docker container
Docker : How to find the network my container is in?
https://docs.docker.com/network/
https://docs.docker.com/network/bridge/
I have a spring-boot project which uses spring-cloud to manage the properties in a centralized place.
I have configured the app as below
#SpringBootApplication
#EnableConfigServer
public class ConfigServerApplication {
public static void main( String[] args )
{
SpringApplication.run(ConfigServerApplication.class, args);
}
}
and the application.properties as below
spring.application.name=spring-cloud-config-server
server.port=8888
spring.cloud.config.server.git.uri=file:///ebs/payment-config-server-git
But when I run the jar, the application log stops at,
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.0.RELEASE)
2020-06-08 19:36:38.641 INFO 4278 --- [ main] c.h.t.c.ConfigServerApplication : No active profile set, falling back to default profiles: default
2020-06-08 19:36:40.303 INFO 4278 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=cb4015b1-4a5b-3c4c-a050-3196b94db932
2020-06-08 19:36:40.973 INFO 4278 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8888 (http)
2020-06-08 19:36:41.001 INFO 4278 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-06-08 19:36:41.002 INFO 4278 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.35]
2020-06-08 19:36:41.128 INFO 4278 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-06-08 19:36:41.128 INFO 4278 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2460 ms
2020-06-08 19:36:41.608 INFO 4278 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-06-08 19:36:42.649 INFO 4278 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-06-08 19:36:42.718 INFO 4278 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8888 (http) with context path ''
2020-06-08 19:36:42.738 INFO 4278 --- [ main] c.h.t.c.ConfigServerApplication : Started ConfigServerApplication in 5.573 seconds (JVM running for 6.371)
It is supposed to log the repository location from where it reads the properties from. But it is not printing those logs and I am not able to read any properties from the application.
What is the mistake in my configuration file?
Thank You.
PS: Git origin is not set. There is no remote for the git repository
I have created a docker file from maven spring boot application and created a docker image and pushed it to my docker registry.
FROM openjdk:8
ADD target/spring-boot-lazy-init-example-0.0.1-SNAPSHOT.jar spring-boot-lazy-init-example-0.0.1-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "spring-boot-lazy-init-example-0.0.1-SNAPSHOT.jar"]
this is the content what I have written inside docker file and created a docker image. I have changed the tag and pushed it to my docker hub repository which I will use for deployment purpose in Kubernetes cluster but before that I have used this docker image for testing purpose. I have used this docker image to run a container and I have also done the port forwarding as application was running on 8080 port by default.
ubuntu#dockerimage-vm:~/spring-boot-lazy-init-example$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
96963/spring-boot-new v1 1e4a8aab28f8 3 days ago 526MB
96963/docker-spring-boot v1 2f2a3b1c23e8 8 days ago 526MB
docker-spring-boot-new latest 2f2a3b1c23e8 8 days ago 526MB
openjdk 8 f8146facf376 2 weeks ago 488MB
ubuntu#dockerimage-vm:~$ sudo docker run -it 96963/spring-boot-new:v1 -p 8085:8080
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.0.M1)
2020-01-17 11:38:21.417 INFO 1 --- [ main] t.l.SpringBootLazyInitExampleApplication : Starting SpringBootLazyInitExampleApplication v0.0.1-SNAPSHOT on 03ab2d24c370 with PID 1 (/spring-boot-lazy-init-example-0.0.1-SNAPSHOT.jar started by root in /)
2020-01-17 11:38:21.426 INFO 1 --- [ main] t.l.SpringBootLazyInitExampleApplication : No active profile set, falling back to default profiles: default
2020-01-17 11:38:23.355 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2020-01-17 11:38:23.451 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 67ms. Found 0 repository interfaces.
2020-01-17 11:38:24.391 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$cf2fe8c5] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-01-17 11:38:25.625 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-01-17 11:38:26.191 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-01-17 11:38:26.192 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.16]
2020-01-17 11:38:26.258 INFO 1 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2020-01-17 11:38:26.486 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-01-17 11:38:26.489 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4929 ms
2020-01-17 11:38:27.532 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-01-17 11:38:28.182 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-01-17 11:38:28.398 INFO 1 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2020-01-17 11:38:28.627 INFO 1 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.0.Final}
2020-01-17 11:38:28.640 INFO 1 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2020-01-17 11:38:29.171 INFO 1 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-01-17 11:38:29.438 INFO 1 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-01-17 11:38:30.312 INFO 1 --- [ main] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl#1b11171f'
2020-01-17 11:38:30.337 INFO 1 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-01-17 11:38:30.339 INFO 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-01-17 11:38:30.694 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-01-17 11:38:30.701 INFO 1 --- [ main] t.l.SpringBootLazyInitExampleApplication : Started SpringBootLazyInitExampleApplication in 10.338 seconds (JVM running for 11.976)
2020-01-17 12:08:38.990 WARN 1 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=28m10s615ms885µs724ns)
I have also tried to run the application from local machine and I am able to reach the url
but while I am trying to reach the application which is running inside docker container I am not able to reach. I am accessing that from 192.168.64.3:8085/lazy, (8085 because I have done the port forwarding at that port).
I have two small Spring Boot applications that exposes a rest API:
app-one
Get Request
- http://localhost:8010/api/stock/AAPL
Response:
{
"name": "AAPL",
"value": 219.9
}
app-two
Get Request
- http://localhost:8080/api/trade/APPL/buy/10
Response
{
"id": 1,
"stock": {
"name": "APPL",
"value": 219.9
},
"quantity": 10,
"total": 2199.0
}
When I run this two apps on my localhost without Docker I get the correct response from both APIs.
When I run the apps using the Docker Compose, the first API app-one responds OK, but the app-two returns an error:
"message": "I/O error on GET request for \"http://127.0.0.1:8010/api/stock/APPL\": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)",
"path": "/api/trade/APPL/buy/10"
This is my docker-compose.yml configuration file:
version: "3.7"
services:
app-one:
image: ibercode/app-one
ports:
- "8010:8010"
expose:
- "8010"
app-two:
build: .
ports:
- "8080:8080"
depends_on:
- app-one
environment:
- APP_ONE_URI=http://127.0.0.1:8010/api/stock/
And this is the output after I run the command docker-compose up
$ docker-compose up
Starting app-two_app-one_1 ... done
Starting app-two_app-two_1 ... done
Attaching to app-two_app-one_1, app-two_app-two_1
app-one_1 |
app-one_1 | . ____ _ __ _ _
app-one_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
app-one_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
app-one_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
app-one_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
app-one_1 | =========|_|==============|___/=/_/_/_/
app-one_1 | :: Spring Boot :: (v2.1.8.RELEASE)
app-one_1 |
app-one_1 | 2019-09-18 08:28:07.287 INFO 1 --- [ main] com.ibercode.AppOneApplication : Starting AppOneApplication vlatest on a090eb18a661 with PID 1 (/app.jar started by root in /)
app-one_1 | 2019-09-18 08:28:07.291 INFO 1 --- [ main] com.ibercode.AppOneApplication : No active profile set, falling back to default profiles: default
app-two_1 |
app-two_1 | . ____ _ __ _ _
app-two_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
app-two_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
app-two_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
app-two_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
app-two_1 | =========|_|==============|___/=/_/_/_/
app-two_1 | :: Spring Boot :: (v2.1.8.RELEASE)
app-two_1 |
app-two_1 | 2019-09-18 08:28:08.308 INFO 1 --- [ main] com.ibercode.AppTwoApplication : Starting AppTwoApplication vlatest on 973897f9ea8d with PID 1 (/app.jar started by root in /)
app-two_1 | 2019-09-18 08:28:08.325 INFO 1 --- [ main] com.ibercode.AppTwoApplication : No active profile set, falling back to default profiles: default
app-one_1 | 2019-09-18 08:28:10.448 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8010 (http)
app-one_1 | 2019-09-18 08:28:10.536 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
app-one_1 | 2019-09-18 08:28:10.537 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
app-one_1 | 2019-09-18 08:28:10.731 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
app-one_1 | 2019-09-18 08:28:10.744 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3313 ms
app-one_1 | 2019-09-18 08:28:11.283 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
app-two_1 | 2019-09-18 08:28:11.488 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
app-two_1 | 2019-09-18 08:28:11.588 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
app-two_1 | 2019-09-18 08:28:11.588 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
app-one_1 | 2019-09-18 08:28:11.701 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8010 (http) with context path ''
app-one_1 | 2019-09-18 08:28:11.705 INFO 1 --- [ main] com.ibercode.AppOneApplication : Started AppOneApplication in 5.488 seconds (JVM running for 6.129)
app-two_1 | 2019-09-18 08:28:11.797 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
app-two_1 | 2019-09-18 08:28:11.797 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3281 ms
app-two_1 | 2019-09-18 08:28:12.077 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
app-two_1 | 2019-09-18 08:28:12.249 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
app-two_1 | 2019-09-18 08:28:12.251 INFO 1 --- [ main] com.ibercode.AppTwoApplication : Started AppTwoApplication in 5.016 seconds (JVM running for 5.955)
Any idea or suggestions?
Thanks
It seem you are trying to access app-1 from app-2 with the URL http://127.0.0.1:8010/api/stock/APPL. However you can't access the other container under 127.0.0.1 from another container.
You can access another service in the compose file by service name. That means, you need to configure your app-2 application to look for the host app-one, i.e. APP_ONE_URI=http://app-one/api/stock/.
You can read more about Compose networking here https://docs.docker.com/compose/networking/.