#Java Spring Boot application doesn't launch on Docker as a container. Database connection exception

20 messages · Page 1 of 1 (latest)

hallow glacier
#

For unknown reasons my docker container doesn't launch Spring Boot application even if in properties I show path to postgres-container:
spring.datasource.url=jdbc:postgresql://postgres-container/maitinimas02
I built an image docker build -t back-end:1 .
And launched the container: winpty docker run -it --network db-network -p 8080:8080 back-end:1
but I still have an error:

2023-03-22 14:21:40.005 ERROR 7 --- [           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:331) ~[postgresql-42.3.5.jar!/:42.3.5]
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.3.5.jar!/:42.3.5]
//....
Caused by: java.net.UnknownHostException: postgres-container

Do you know how to launch the container?
postgress-container is running on Docker-Desktop with explicitly mapped ports 5432:5432.

ocean zephyrBOT
#

This post has been reserved for your question.

Hey @hallow glacier! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

upbeat night
#

Did you create a common network for these images and make them use it?

hallow glacier
#

I created db-network using command: docker network create db-network And it was created.

upbeat night
#

Uhuh. And do the containers use it?

hallow glacier
#

I haven't used db-network while created postgres-container: docker run -p 5432:5432 --name postgres-container -e POSTGRES_PASSWORD=tommoc0123 -d postgres:alpine3.17

#

But I used it to create back-end container: winpty docker run -it --network db-network -p 8080:8080 back-end:1

upbeat night
#

Okay so I don't have my docker env ready here to verify. But I thought that containers were isolated from each other if not using a common named network

hallow glacier
#

In the end I'm not sure which containers do use the network

#

I'm new here

#

Yes containers are isolated. And can connect only through specific network

hallow glacier
#

Ok I solved current error.

#

Though I got a new one. Which is very Spring Boot-ish:

#
2023-03-22 15:29:00.286 ERROR 7 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userPasswordResetService': Unsatisfied dependency expressed through fiel
d 'encoder'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency
 expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userS
ervice': Unsatisfied dependency expressed through field 'encoder'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating
 bean with name 'getPasswordEncoder': Requested bean is currently in creation: Is there an unresolvable circular reference?
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor
.java:659) ~[spring-beans-5.3.20.jar!/:5.3.20]

#
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through fie
ld 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied d
ependency expressed through field 'encoder'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'getPa
sswordEncoder': Requested bean is currently in creation: Is there an unresolvable circular reference?
#

The app works perfectly while not in the container.

ocean zephyrBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

hallow glacier
#

Solved the problem. If you need to know how them PM me and ask.

ocean zephyrBOT