Background of 0.
My Docker-compose deployed my SrpingBoot microservice in the Docker container, but it always failed to connect to the Euraka server when deploying Euraka. After various search, I finally solved the problem and recorded the cost document.
1. Problem description
The Euraka client that is about to connect will say “connection refused” when connecting to Euraka, or “service cannot be found”
2. Solve
Ensure the following configurations:
- 1) Spring. Application. Name specified in application. For example, I call it eureka.
- 2) Docker-comemess. yaml configuration file contains a service named “Eureka” under the services configuration file, the same name as above.
- 3) Focus, focus, focus. Client service configuration. In the docker-comemater.yaml configuration file, the important configuration items in the client service to connect to Enreka are as follows: (a). Specify links: -eureka. (b). Configure the environment variables (environment) : EUREKASERVER_URI: “http://eureka:8761/eureka/”
- 4) client micro service engineering application in the directory. The yml configuration eureka. Client. ServiceUrl. DefaultZone: ${EUREKASERVER_URI:http://localhost:8761/eureka/}
Note: The Links configuration item specifies that the Docker client microservice is connected by the name Eureka. Then you can use http://eureka:8761/eureka/ configuration found service address.
3. Appendix: My configuration file
Application. Yml of Eureka engineering
Server: port: ${port: 8761} Spring: Application: name: Eureka # Profiles: active: dev Eureka: FetchRegistry: false # register a service from Eureka waitTimeInMsWhenSyncEmpty: 5Copy the code
Docker-comemess. configuration file docker-comemess. yaml
Version: '3.1' Services: Eureka: build:./ Eureka-service ports: -8671:8761 Environment: PORT: "8761" PROFILE: "dev" zuul: build: ./zuul ports: - 11111:11111 links: - eureka environment: PORT: "11111" PROFILE: "dev" EUREKA_SERVER: "eureka" EUREKASERVER_PORT: "8761" EUREKASERVER_URI: "http://eureka:8761/eureka/" article: build: ./article-service links: - eureka environment: PORT: "11400" PROFILE: "dev" EUREKA_SERVER: "eureka" EUREKASERVER_PORT: "8761" EUREKASERVER_URI: "http://eureka:8761/eureka/" user: build: ./user-service links: - eureka environment: PORT: "11300" PROFILE: "dev" EUREKA_SERVER: "eureka" EUREKASERVER_PORT: "8761" EUREKASERVER_URI: "http://eureka:8761/eureka/"Copy the code
Application. Yml of client microservice project
Server: port: ${port: 11111} Spring: application: name: zuul true client: registerWithEureka: true fetchRegistry: true serviceUrl: defaultZone: ${EUREKASERVER_URI:http://localhost:8761/eureka/}Copy the code
END