-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to tell eureka client running in Docker to use host's IP #432
Comments
I wonder if |
And what about:
|
Difficult to tell from looking at the class in isolation. Depends on |
@cer maybe an option to disable the refresh |
I haven't looked at Spring Cloud enough to know precise what refresh is |
Maybe I don't get it, but setting @cer: the user specified value takes precedence over the default values. Do you see a different behaviour? |
@spencergibb Ok - I see. Sorry, I wasn't aware of that change. |
@cer @spencergibb Having a slightly more complicated version of the same problem. I am experiencing the same issue for the host. On top of that the container is launched with -P meaning a random host port is assigned. With the current setup there is no way to get that random port assignment. The port is being pulled from Another note, about assigning something within |
Something that can be done from docker is just using the Not sure yet how to handle this for a cluster. |
Update: Further testing with AWS ECS even with adding the hostname to the properties it does not work. Unless all instances are docker containers i.e. Eureka, Zuul and UI and API services on the same host. Not sure If I am missing something. It seems that Ribbon is looking for something different than what Eureka is showing via the UI. Even if I could get it to work. As soon as the docker container switched to a different EC2 container the old hostname would be invalid. |
What do you mean by "docker container switched to a different EC2 container" exactly? |
@cer In ECS you have a cluster of EC2 instances. Due to the nature of EC2 unless you specify a Service to run on only one EC2 instance it can appear anywhere within the cluster. That being said I now have ECS working for Spring Cloud. The solution is to curl the hostname of the host from within the Docker container during its boot process and assign the hostname to an environment variable. Then add the discovered hostname to the Eureka instance metadata. |
@rozhok Are you doing something like the below? This is how I managed to get ECS to work. entrypoint.sh
Dockerfile
|
No, I've created custom Eureka Config so I don't need to setup additional scripts in Dockerfile. All stuff are described in #30 . |
Another one approach described in Spring Cloud Netflix docs: @Bean
@Profile("docker")
public EurekaInstanceConfigBean eurekaInstanceConfig() {
EurekaInstanceConfigBean config = new EurekaInstanceConfigBean();
AmazonInfo info = AmazonInfo.Builder.newBuilder().autoBuild("eureka");
config.setDataCenterInfo(info);
info.getMetadata().put(AmazonInfo.MetaDataKey.publicHostname.getName(), info.get(AmazonInfo.MetaDataKey.publicIpv4));
config.setHostname(info.get(AmazonInfo.MetaDataKey.publicHostname));
config.setIpAddress(info.get(AmazonInfo.MetaDataKey.publicIpv4));
config.setNonSecurePort(port);
return config;
} This will put proper IP (public in my case, but you may change it to local) and port into Eureka registry.
|
@cer @rozhok @brenuart @ccit-spence anyone still having issues that we need to address? |
My solution works fine for me. |
@spencergibb I'm using solution described above. A little bit hackish but fine at the moment. |
I'm fine with this. |
It can be used to do my own server not AWS?
|
@Dreampie not, it won't be used on your own infrastructure since it using AWS-specific SDK. |
@rozhok thank you. and how can eureka client registered with host ip,not docker container ip?if use --net=host always return 127.0.0.1 |
Use some env variables passed into docker on startup time.
|
@rozhok but if this machine's ip changed, must recreate container? |
Sure.
|
Or trigg some API insinde container to reload eureka configuration.
Something like /api/eureka/changeIp etc. There is a lot of ways to solve
this task but non of them are obvious or elegant. Sad.
|
💦thanks |
@Dreampie Using the custom Eureka config as in your post, what do the |
is there any update about this issue? |
@cswanghan no, it was closed in 2015 |
@spencergibb im still facing the issue |
@momentum123 |
EurekaInstanceConfigBean is private in that package .. not sure how this would be implemented. |
Line 42 in c60b6db
|
It's the class that is Line 287 in c60b6db
I have the same issue running my app inside DevContainer (docker behind the scenes). |
Use the public constructor.
|
I am running a Spring Cloud application inside a Docker container.
While I can tell Eureka to use the exposed port (e.g.
EUREKA_INSTANCE_NON_SECURE_PORT: 8081
) , it doesn't seem to let you tell it to register using the host's ip address.Instead, eureka registers the instance using the container's ip address.
That fine unless I want to access the container from another host.
What would be great is the ability to set an environment variable such as
EUREKA_INSTANCE_NON_SECURE_HOST: docker_host_ip_address
The text was updated successfully, but these errors were encountered: