gpt4 book ai didi

docker - 如何链接在AWS ECS任务中运行的2个容器

转载 作者:行者123 更新时间:2023-12-02 17:52:16 26 4
gpt4 key购买 nike

我是ECS的新手,我正尝试使用Fargate在ECS任务中部署几个容器。

我有一个正在运行的容器,该容器使用Angular2,并且在nginx上运行,另一个容器是后端,并且在Springboot上运行,并使用端口42048。

我将awsvpc网络与Fargate一起使用,我必须这样做。

Angular应用程序使用localhost:42048/some_url与后端进行通信,并且在我的本地docker中可以正常工作,但在AWS中,前端找不到后端。目前,我的端口映射为80的前端和42048的后端,而在本地部署时,前端能够以localhost:42048的方式找到后端

任何帮助,将不胜感激。谢谢

最佳答案

AWSVPC中不允许链接。

当设置为桥接时,您只能在网络模式下进行链接。

links

Type: string array

Required: no

The link parameter allows containers to communicate with each other without the need for port mappings. Only supported if the network mode of a task definition is set to bridge. The name:internalName construct is analogous to name:alias in Docker links. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed. For more information about linking Docker containers, go to https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/. This parameter maps to Links in the Create a container section of the Docker Remote API and the --link option to docker run.



注意

Windows参数或使用awsvpc网络模式的任务不支持此参数。

重要的

并置在单个容器实例上的容器可能能够彼此通信,而无需链接或主机端口映射。使用安全组和VPC设置可以在容器实例上实现网络隔离。

task_definition_parameters

在网络模式下,您必须在相同的任务定义中定义两个容器,然后在链接中提到该容器的名称。

enter image description here
然后在前端容器中提到后端容器的名称。

enter image description here

关于docker - 如何链接在AWS ECS任务中运行的2个容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56535632/

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