Containers可以与端口通信吗?ECS在EC2上

huangapple go评论57阅读模式
英文:

containers can communicate with ports? ECS on EC2

问题

我正在将我的项目从在Fargate上的ECS迁移到在EC2上的ECS

现在我遇到了一些容器通信的问题。

从EC2节点,我可以看到有两个容器正在工作。

然后我登录到了EC2节点上的容器。

$ docker exec -it 654e3b4370f6 /bin/bash # 登录nginx容器

然后在容器的shell中。

root@654e3b4370f6:/# curl localhost:8011 # 连接到django容器

然而,它显示curl: (7) Failed to connect to localhost port 8011: Connection refused

为什么会发生这种情况?

当我使用Fargate时,容器可以使用这种方法相互联系。

我不能在EC2上的ECS上使用端口吗?

英文:

I am moving my project from ECS on fargate to ECS on EC2

Now I have some troubles containers comunication.

f91bc9ec2092   678100221111.dkr.ecr.ap-northeast-1.amazonaws.com/ol-dev-django:latest   "./entrypoint.fargat…"   11 seconds ago   Up 9 seconds              0.0.0.0:8011->8011/tcp, :::8011->8011/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   ecs-oldevecsTaskDefinition4BE5F675-24-ol-django-container-bef283fff2ff8d876f00
654e3b4370f6   678100221111.dkr.ecr.ap-northeast-1.amazonaws.com/ol-dev-nginx:latest    "/docker-entrypoint.…"   11 seconds ago   Up 9 seconds              0.0.0.0:80->80/tcp, :::80->80/tcp                                                      ecs-oldevecsTaskDefinition4BE5F675-24-ol-nginx-container-d0bda396a09d84e6d601

From EC2 Node, I can see two containers are working.

then I login the container with EC2 node.

$docker exec -it 654e3b4370f6 /bin/bash` #login nginx container.

then in the container shell.

root@654e3b4370f6:/#curl localhost:8011` #connect to django container

However it says curl: (7) Failed to connect to localhost port 8011: Connection refused

WHy this happens ?

When I am using Fargate, containers can contact each other with this methods.

I can not use port on ECS on EC2?

答案1

得分: 1

AWS Fargate仅支持ECS任务的awsvpc网络模式。在awsvpc网络模式下,容器可以通过localhost相互通信。

EC2支持ECS任务的多种网络模式,并默认使用bridge网络模式。如果您希望容器能够通过localhost相互通信,并在其他方面表现与在Fargate上运行时相同,则需要配置ECS部署的任务以使用awsvpc网络模式。

英文:

AWS Fargate only supports the awsvpc Network mode for ECS tasks. In awsvpc Network mode containers can communicate with each other over localhost.

EC2 supports several network modes for ECS tasks, and default to bridge network mode. If you want your containers to be able to communicate with each other over localhost and otherwise behave the same that they did when they were running on Fargate, then you need to configure your ECS deployed tasks to use awsvpc Network mode.

huangapple
  • 本文由 发表于 2023年5月13日 21:51:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76243076.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定