Currently we are having issues when restarting services because they have fixed ports and our cluster is nearing full capacity. If the ECS agent could control the random port and make it available inside the container as an environment variable, our service registration/discovery could pick up the details and save it in etcd. It would also be helpful if the host private and public ip addresses were also available. Messos does it this way. This is also helpful when running multiple similar services on the same host. e.g. One service for each end user.
I think this issue relates to #3, though ports haven't been specifically mentioned there.
I'm marking this as a feature request for now, though if #3 gets expanded upon to very clearly cover this I might close in favour of that one.
Thanks for sharing the details of your use case,
Euan
I also need this feature. In my case the application running inside a container have to register itself against a service registry (Netflix eureka or Consul) and to do so it needs the host IP and port.
This would be really useful for running Selenium nodes on ECS, among other things. Please consider this.
+1
+1
+1
As much as I hate +1 comments this issue along with #3 are essential. While there are workarounds for both issues they require extra work for what seems like very common use case.
I really hope these two issues get the attention they deserve.
@MaikuMori We're definitely paying attention to these. +1 comments are helpful in seeing interest but use-case details can help us make sure we build the right thing.
@samuelkarp I guess my use-case is fairly standard - registering service with consul from within the container.
Currently I'm registering them at the same place where they are scheduled, but it would be nice if containers could register themselves, because each container knows what it is providing and expecting. It's slightly annoying to put this logic into what would be a general/universal scheduler.
@samuelkarp For me the same use-case: discovery service eureka from with the container. Need to now the assign dynamic host port in the container.
@samuelkarp For me, it's the same case. I'm using Spring-boot + Spring-cloud-netflix + Eureka and I need to know what random port was mapped to that container for start my services properly.
+1
+1
+1 Same use case, Eureka discovery
+1 Another consul service discovery use case. Currently this can be circumvented with an overlay network, but I would rather not have to run an overlay network if I don't have to. Allowing services to register with the instance ip + random exposed port would solve that problem.
My use case: We're are running Kong API gateway as containers on ECS using dynamic port mapping so that we can scale beyond the number of instances in the ECS cluster.
Kong however is a clustered service and requires that each container advertise its address:port via ENV vars.
Without the ability to get port mappings from the ENV we're forced to either write a complex entrypoint that does a describe_task, or go back to static port mappings. Neither case is ideal.
I think it might be possible to auto-assign ports using new Application Load Balancers with the ecs-agent.
@talentedmrjones - can you please share some info how you were able to do with describe_task, I have something similar for hazelcast docker applications where I need to publish the public address as
This is must requirement for AWS ECS and need to accessible inside docker container.
@AjitDas I haven't actually written that script yet, but in theory via entrypoint shell script you could get the port mappings and set those as ENV vars before then executing the containers application
For those looking for a solution, I wrote this script to export the port mappings as environment variables https://gist.github.com/chris-smith-zocdoc/126db78651046c67ac66dbd87393b1dc
Note that your container will need permissions to the ecs describe_tasks api
Same, we need this to run Kong in production. Without knowledge of the mapped port we can't register the node for discovery.
+1 Another Eureka registration case here.
+1 Another Eureka registration case here.
+1 for Selenium Grid on top of ECS
We really need the ability detect host ip and port inside container to register service to Eureka server.
@euank Any update on if/when this will land? It's been open for a few months shy of 2 years.
Hi @bndw, thanks for reaching out to us. We are planning to address the make available as env variables bit as a part of the Container Metadata proposal, which is currently being reviewed in #709. Feel free to add details about your use-case if #709 addresses your use-case.
Thanks,
Anirudh
Any updates this, while I assume many have found workarounds considering the amount of time which has past I still things its critical this get implemented.
Thanks,
Serge
We have released ECS agent v1.15.0, which adds support for retrieving dynamic port assignment from within the container. Please see the documentation for information on how to use it.
Thanks @samuelkarp for the update on Metadata file .
Finally was able to register my ecs spring boot app container started with an dynamic host port to eureka .
*Steps were*
(not an efficient bash script though :)
And referenced that EXPOSED_PORT in my bootstrap.yml , under eureka-section, which is referenced during the spring boot app startup.
non-secure-port: ${EXPOSED_PORT}
@sunilram86 Just a heads up--
You probably want to ensure MetadataFileStatus has value of READY before looking for a HostPort. In my experience with ECS APIs, ports are not always present when tasks are in a PENDING state.
@bndw Thanks for the heads up , will check for READY in MetadataFileStatus before looking for a HostPort.