'Spring boot client doesn't register to Spring admin on docker
Hello to all developers.
I have a problem and I have been struggling with it for a few days but I can not solve it.
The problem is I have two dockerized Spring application, one of them is admin and another is client. When I run these two out of Docker, the client registers with the admin without any problem, and I can see the client from the admin dashboard. But when I try to run these two as two containers in Docker with a Docker network, the client application gives this error:
de.codecentric.boot.admin.client.registration.DefaultApplicationRegistrator: Failed to register application as Application(name=spring client, managementUrl=http://545ade59e8dc:8585/actuator, healthUrl=http://545ade59e8dc:8585/actuator/health, serviceUrl=http://545ade59e8dc:8585/) at spring-boot-admin ([http://localhost:8080/instances]): I/O error on POST request for "http://localhost:8080/instances": Connection refused; nested exception is java.net.ConnectException: Connection refused. Further attempts are logged on DEBUG level
The admin application's docker-compose.yml file:
version: '3.3'
networks:
spring-admin-network:
driver: bridge
services:
spring-admin:
build:
context: .
args:
JAR_FILE: "./target/spring-admin-1.0.0.jar"
image: spring-admin
container_name: spring-admin
ports:
- "127.0.0.1:8080:8585"
networks:
- spring-admin-network
And the client application's docker-compose.yml file:
version: '3.3'
networks:
spring-admin-network:
driver: bridge
services:
repo-reporter:
build:
context: .
args:
JAR_FILE: "./target/spring-client-1.0.0.jar"
image: spring-client
container_name: spring-client
ports:
- "127.0.0.1:8081:8585"
networks:
- spring-admin-network
And application.properies for admin application:
spring.application.name=spring-admin
server.port=8585
spring.security.user.name=admin
spring.security.user.password=admin
And application.properies for client application:
spring.application.name=spring-client
server.port=8585
server.compression.enabled=true
server.http2.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
spring.boot.admin.client.url=http://localhost:8080
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=admin
spring.boot.admin.client.instance.metadata.user.name=${spring.security.user.name}
spring.boot.admin.client.instance.metadata.user.password=${spring.security.user.password}
The commands I execute:
docker network create spring-admin-network
...Some hash...
cd /spring-admin
docker-compose build
...Successfully built...
docker-compose up -d
...Creating network "springadmin_spring-admin-network" with driver "bridge"
Creating spring-admin ... done...
cd ../spring-client
docker-compose build
...Successfully built...
docker-compose up -d
...Creating network "springclient_spring-admin-network" with driver "bridge"
Creating spring-client ... done...
docker logs -f spring-client
.
.
.
de.codecentric.boot.admin.client.registration.DefaultApplicationRegistrator: Failed to register application as Application(name=spring client, managementUrl=http://545ade59e8dc:8585/actuator, healthUrl=http://545ade59e8dc:8585/actuator/health, serviceUrl=http://545ade59e8dc:8585/) at spring-boot-admin ([http://localhost:8080/instances]): I/O error on POST request for "http://localhost:8080/instances": Connection refused; nested exception is java.net.ConnectException: Connection refused. Further attempts are logged on DEBUG level
Thanks in advance.
Solution 1:[1]
Docker creates a new docker network when you build and run the docker-compose file. as an example
xxx_spring-admin-network (for admin application)
yyy_spring-admin-network (for client application)
you can check by
docker network ls
First and foremost, you should set up a Docker network.
docker network create spring-admin-network
then make a docker-compose.yml change Both files should point to an existent network.
version: '3.3'
networks:
spring-admin-network:
external: true
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Goffity |
