[英]Eureka Client with Docker Compose
I am trying to containerize one of my microservices using docker.我正在尝试使用 docker 容器化我的一项微服务。
Below is the dokerfile content下面是 dockerfile 内容
FROM openjdk:8-jdk-alpine
LABEL maintainer="shardajaiswal@gmail.com"
RUN mkdir -p /test/service/master/input/
RUN mkdir -p /test/service/master/output/
VOLUME /test/service/master/input/
VOLUME /test/service/master/output/
EXPOSE 8080
ARG JAR_FILE=target/master-1.1-SNAPSHOT.jar
ADD ${JAR_FILE} master-1.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar","master-1.1-SNAPSHOT.jar"]
I have created image using maven plugin successfully.我已经成功地使用 maven 插件创建了图像。
Now when I try to run the image using the below command on docker CLI the service is up and running fine现在,当我尝试在 docker CLI 上使用以下命令运行图像时,服务已启动并运行良好
docker run -p 7070:8080 -e spring.cloud.config.username=username123
-e \spring.cloud.config.password=password123
-e \spring.cloud.config.failFast=true
-e \spring.cloud.config.discovery.enabled=true
-e \eureka.client.serviceUrl.defaultZone=http://username123:password123@10.XXX.21.161:31120/eureka/,http://username123:password123@10.XXX.147.171:31120/eureka/
-e \spring.profiles.active=staging,XYZServerName shardaspj:master-1.1-SNAPSHOT
With above command from command line, its able to connect to config server and also able to register with Eureka.使用上面的命令行命令,它可以连接到配置服务器,也可以注册到 Eureka。
Now I want to run the service using docker-compose.yml file since I want to add certain other parameters as well to the configuration.现在我想使用 docker-compose.yml 文件运行该服务,因为我还想将某些其他参数添加到配置中。
My docker-compose.yml file looks like below:-我的 docker-compose.yml 文件如下所示:-
version: '3.0'
services:
master:
container_name: master
image: shardaspj:master-1.1-SNAPSHOT
environment:
SPRING_CLOUD_CONFIG_USERNAME: username123
SPRING_CLOUD_CONFIG_PASSWORD: password123
SPRING_CLOUD_CONFIG_FAILFAST: 'true'
SPRING_CLOUD_CONFIG_DISCOVERY_ENABLED: 'true'
EUREKA_CLIENT_SERVICE-URL_DEFAULTZONE: http://username123:password123@10.XXX.21.161:31120/eureka/,http://username123:password123@10.XXX.147.171:31120/eureka/
SPRING_PROFILES_ACTIVE: staging,XYZServerName
ports:
- "7070:8080"
But on running the command docker-compose up on command line I am getting the below error and not able to connect to register on eureka and also not connecting to config server to fetch the configuration files.但是在命令行上运行命令 docker-compose up 时,我收到以下错误,无法连接到 eureka 上注册,也无法连接到配置服务器以获取配置文件。
master | 2018-07-18 11:18:51.867 WARN [master,,,] 1 --- [ main] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connectio
n refused (Connection refused)
master | 2018-07-18 11:18:51.873 ERROR [master,,,] 1 --- [ main] com.netflix.discovery.DiscoveryClient : DiscoveryClient_MASTER/cd656dee7969:master - was unable to refresh its cach
e! status = Cannot execute request on any known server
master |
master | com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
master | at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111)
master | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)
master | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137)
master | at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
master | at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)
master | at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1022)
master | at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:936)
master | at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:412)
master | at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:267)
master | at org.springframework.cloud.netflix.eureka.CloudEurekaClient.<init>(CloudEurekaClient.java:61)
master | at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$EurekaClientConfiguration.eurekaClient(EurekaClientAutoConfiguration.java:234)
master | at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$EurekaClientConfiguration$$EnhancerBySpringCGLIB$$f480408d.CGLIB$eurekaClient$0(<generated>)
master | at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$EurekaClientConfiguration$$EnhancerBySpringCGLIB$$f480408d$$FastClassBySpringCGLIB$$cdb46f4f.invoke(<gener
ated>)
Also down the logs getting error:-还记录了错误:-
2018-07-18 11:18:51.876 WARN [master,,,] 1 --- [ main] com.netflix.discovery.DiscoveryClient : Using default backup registry implementation which does not do anything.
2018-07-18 11:18:51.886 INFO [master,,,] 1 --- [ main] com.netflix.discovery.DiscoveryClient : Not registering with Eureka server per configuration
2018-07-18 11:18:51.951 INFO [master,,,] 1 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1531912731950 with initial instances count : 0
2018-07-18 11:18:53.381 WARN [master,,,] 1 --- [ main] lientConfigServiceBootstrapConfiguration : Could not locate configserver via discovery
java.lang.IllegalStateException: No instances found of configserver (registry)
at org.springframework.cloud.config.client.ConfigServerInstanceProvider.getConfigServerInstance(ConfigServerInstanceProvider.java:25)
at org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration.refresh(DiscoveryClientConfigServiceBootstrapConfiguration.java:80)
at org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration.startup(DiscoveryClientConfigServiceBootstrapConfiguration.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:256)
at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:177)
at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:140)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
Please help me with setting up the docker-compose.yml correctly.请帮助我正确设置 docker-compose.yml。
You are probably better off blanking out all the values for the environment variables in your docker-compose file and putting them in a .env file at the same level as your docker-compose file.您最好将 docker-compose 文件中环境变量的所有值清空,并将它们放在与 docker-compose 文件相同级别的 .env 文件中。 The format of this file is key=value, one per line.
这个文件的格式是key=value,每行一个。 That way you can re-use your compose file in different environments.
这样您就可以在不同的环境中重复使用您的撰写文件。
Then do a docker-compose config to see how the environment variables are plugged into your docker-compose set up.然后执行 docker-compose 配置以查看环境变量如何插入到您的 docker-compose 设置中。
I think the issue you have is you are missing hyphens.我认为您遇到的问题是您缺少连字符。 Instead of this:
取而代之的是:
environment:
SPRING_CLOUD_CONFIG_USERNAME
SPRING_CLOUD_CONFIG_PASSWORD
SPRING_CLOUD_CONFIG_FAILFAST
You need something like this:你需要这样的东西:
environment:
- SPRING_CLOUD_CONFIG_USERNAME
- SPRING_CLOUD_CONFIG_PASSWORD
- SPRING_CLOUD_CONFIG_FAILFAST
Running docker-compose config after you've moved the values into .env will show if you've got it all working OK.在将值移动到 .env 后运行 docker-compose config 将显示是否一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.