如何在AWS ECS中执行同一任务的容器之间进行通信?

编程入门 行业动态 更新时间:2024-10-09 15:17:26
本文介绍了如何在AWS ECS中执行同一任务的容器之间进行通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 service-A ,其任务定义为 task-A ,其中包括多个容器定义,例如 nginx 和grafana .这些容器如何相互通信?使用的网络是默认的桥接网络.

I have a service-A with a task definition task-A that includes multiple container definitions, for example nginx and grafana. How can these containers communicate with each other? The network used is the default bridge network.

我尝试了 curl grafana:3000 ,但是容器无法解析名称.如果我在本地计算机上尝试相同的方法,它将可以正常工作.我想念什么?

I have tried curl grafana:3000, but the container is not able to resolve the name. If I would try the same on my local machine it would work. What am I missing?

这是我的任务定义:

resource "aws_ecs_task_definition" "this" { family = "x" execution_role_arn = "x" task_role_arn = "x" container_definitions = jsonencode(local.task_definition) }

容器定义摘录:

locals { task_definition = [ { name: "nginx", image: "nginx:latest", portMappings: [{ containerPort: 80, hostPort: 0, protocol: "tcp" }], dependsOn: [{ "containerName": "grafana", "condition": "START" }] }, { name: "grafana", image: "grafana/grafana:latest", portMappings: [{ containerPort : 3000, hostPort: 0, protocol: "tcp" }] } ] }

推荐答案

dependsOn 仅在按顺序启动容器时起作用,需要链接以使服务之间进行服务到服务级别的通信.

dependsOn only work to start the container in order, you need linking to make service to service level communication between container.

dependsOn: [{ "containerName": "grafana", "condition": "START" }] "links": [ "grafana" ]

来自文档

links Type: string array Required: no

link参数允许容器相互通信无需端口映射.仅在网络模式下受支持定义的任务集被设置为桥接.名称:internalName构造类似于Docker链接中的name:alias.最多255个字母(大写和小写),数字,连字符和下划线是允许

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

交流相同的任务在aws-ecs中的容器之间

更多推荐

如何在AWS ECS中执行同一任务的容器之间进行通信?

本文发布于:2023-11-27 11:45:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637928.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   通信   如何在   ECS   AWS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!