Reputation: 11
I'm not able to bind a IP:port
to container port in AWS ECS
task definition. Such that on command line,
docker run "-p 172.17.42.1:14242:3000"
172.17.42.1:14242
is IP:port
. But in AWS ECS
there are only two options, hostPort
and containerPort
and they take only integers not strings:
"portMappings": [
{
"hostPort": 14242,
"containerPort": 3000
}
]
So, how can I provide IP:port
in task definition?
When I do (Without IP) port:port
mapping, and after task creation I do:
aws ecs describe-tasks
it shows
0.0.0.0:14242:3000.
But I want specific IP not 0.0.0.0
.
Upvotes: 1
Views: 2292
Reputation: 132
This is not a supported feature as far as I'm aware, and it wouldn't make too much sense on ECS since the ip address of the host instance isn't known ahead of time.
ECS is designed to use all available EC2 instances in a "cluster" to deploy containers belonging to to a service/task. One of ECS's core features is the flexibility to add/remove/update EC2 instances in the cluster in an ad-hoc manner, and allow containers to be deployed on whichever cluster instances has available resources at the particular time when the task is launched. This means there's no guarantee that you'll know the IP address ahead of time when you create the task definition, since you won't know for sure which EC2 instance it will be deployed on.
If you really have a strong use case where you must deploy a task/container on a specific EC2 instance and IP, then you could roll your own solution by interacting directly with the ECS agent. [1][2]
That said, I'd highly recommend re-examining your design and trying to implement it in a way that's host/ip agnostic. For example, you could use Elastic Load Balancer (ELB) in the ECS "service" definition [3] to allow the containers to be reached through a fixed DNS hostname regardless of which IP they're hosted on.
[1] http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_agent.html
[2] https://github.com/aws/amazon-ecs-agent
[3] http://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-load-balancing.html
Upvotes: 2