问题
I'm trying to deploy a ConfigServrService and a Client with a remote repository using DockerCompose.
The docker-compose.yml is like:
version: '2'
services:
rabbitmq:
image: rabbitmq
ports:
- "5672:5672"
config-server:
image: config-server
environment:
- "SPRING_PROFILES_ACTIVE=desa"
ports:
- "8888:8888"
links:
- rabbitmq
depends_on:
- rabbitmq
user-service-config:
image: user-service-config
environment:
- "SPRING_PROFILES_ACTIVE=desa"
ports:
- "8090:8090"
links:
- config-server
- rabbitmq
depends_on:
- rabbitmq
- config-server
At the moment that they are deploying, the client console shows:
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
(Instead of http://config-server:8888)
And after that, the console shows:
Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/user-server-config/desa": Connection refused; nested exception is java.net.ConnectException: Connection refused
The service is trying to connet to http://localhost:8888/user-server-config/desa instead of http://config-server:8888.
The application.yml file of the client is:
server:
port: 8090
spring:
rabbitmq:
host: 172.17.0.1
port: 5672
username: guest
password: guest
application:
name: user-server-config
cloud:
enabled: true
config:
uri: http://config-server:8888
failFast: true
retry:
maxAttempts: 20
management:
security:
enabled: false
I do not know why the uri contains http://localhost:8888 with /user-server-config/desa at the end. Instead of http://server-config:8888 as is indicated in the application.yml
回答1:
As suggested by spencergibb here, and as the official documentation suggests, create a bootstrap.yml
file:
spring:
cloud:
enabled: true
config:
uri: http://config-server:8888
failFast: true
retry:
maxAttempts: 20
and remove the above included properties from application.yml
.
来源:https://stackoverflow.com/questions/43005558/docker-springconfig-connection-refused-to-configserver