在AWS Fargate中链接容器 [英] Linking Container in AWS Fargate

查看:118
本文介绍了在AWS Fargate中链接容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在AWS Fargate上设置一个小示例,并尝试在其中有一个应用程序容器和一个数据库容器.

I try to setup a little example on AWS Fargate and try to have one application container with one database container there.

任务定义同时启动了两个容器,但是我的应用程序容器失败,并显示getaddrinfo ENOTFOUND db db:3306. 因此,我的应用程序容器找不到数据库容器.

The task definition starts both containers, but my app container fails with getaddrinfo ENOTFOUND db db:3306. Therefore, the database container could not be found by my app container.

由于Fargate不允许Docker容器的链接",所以我想知道它们如何相互通信. 数据库容器的名称为db,端口为3306,并且我的应用容器已配置为使用该容器.

Since Fargate does not allow "links" of Docker containers, i'd like to know how they can communicate with each other. The database container has the name db with port 3306 and my app container is configured to use this.

不幸的是,定义容器链接不适用于Fargate,而仅适用于老式" ECS/EC2.

Unfortunately, defining links of containers is not available for Fargate, but only for "oldschool" ECS/EC2.

在本地docker-compose设置中,它正以这种方式工作.

In a local docker-compose setup it is working this way.

推荐答案

Fargate任务中的容器共享一个网络名称空间,因此您根本不需要使用链接.您可以简单地通过本地主机进行通信.

Containers in Fargate tasks share a network namespace, so you don't need to use links at all. You can simply communicate via localhost.

例如,如果您的容器A在端口8000上运行Web服务器,则容器B可以通过curl http://localhost:8000/

For example, if you have container A running a web server on port 8000, container B could reach it with curl http://localhost:8000/

这篇关于在AWS Fargate中链接容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆