Home > other >  Is it possible to get IP from host instance on ECS in bridge mode?
Is it possible to get IP from host instance on ECS in bridge mode?

Time:09-21

I checked many sources online but couldn't find one to specifically answer this.

I already checked the metadata option from inside the container, but in bridge mode, the response to the call to the metadata URL only gives me the IP of the container, not the host EC2 instance.

Is there a way around this?

CodePudding user response:

With the bridge mode, the container shares the same network interface as that of the instance on which it is running, therefore the IP of the container is the same as that of the EC2 instance.

You might find this useful: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html

CodePudding user response:

Using the info from Paolo's answer, I tried using "host" as a Network mode for a new Task that I needed to connect to an existing Task on another Service. I needed to this with as little change as possible to the original Task/Service.

Since I know they will all run on the same EC2 instance, by using "host" as a Network mode I was able to use "localhost" from inside the container to connect to any container running on EC2, even in a different Service/Task.

I'm happy. =)

  • Related