英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论