gpt4 book ai didi

amazon-web-services - 我的Docker化微服务的动态端口设置

转载 作者:行者123 更新时间:2023-12-02 19:57:55 28 4
gpt4 key购买 nike

我想部署我的微服务的多个实例,这些实例使用某些端口,但使其具有可伸缩性,而不是在任务定义/ Dockerfile中修复该端口。我的微服务可以侦听环境变量或命令行中提供的端口。

目前,所有微服务都在AWS ECS任务定义中进行了描述,并具有静态端口分配。
每个微服务都向Eureka服务器注册,现在我只能在不同的EC2实例上运行多个服务实例。

我希望能够在同一个EC2实例上运行多个容器,但是每个新的服务实例都应该有一些可用的端口来监听它。

执行此操作的标准方法是什么?

最佳答案

只需在任务定义中将主机端口设置为0:

If using containers in a task with the EC2 launch type, you can specify a non-reserved host port for your container port mapping (this is referred to as static host port mapping), or you can omit the hostPort (or set it to 0) while specifying a container port and your container automatically receives a port (this is referred to as dynamic host port mapping) in the ephemeral port range for your container instance operating system and Docker version.



enter image description here

The default ephemeral port range is 49153–65535, and this range is used for Docker versions before 1.6.0. For Docker version 1.6.0 and later, the Docker daemon tries to read the ephemeral port range from /proc/sys/net/ipv4/ip_local_port_range (which is 32768–61000 on the latest Amazon ECS-optimized AMI)



因此,在这种情况下,您将需要应用程序LB在动态端口上路由流量。

您可以从本文 dynamic-port-mapping-in-ecs-with-application-load-balancer寻求帮助。

关于amazon-web-services - 我的Docker化微服务的动态端口设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56582069/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com