简体   繁体   English

如何在 2 个 ec2 实例上连接 2 个不同的 docker 容器?

[英]How can I connect 2 different docker containers on 2 ec2 instances?

I have a usecase where I want to run one container on one ec2 and I have 2 such containers.我有一个用例,我想在一个 ec2 上运行一个容器,我有 2 个这样的容器。 I want container one from ec2 1 to access container 2 on ec2 2. How can I bind the 2 containers on different machines with the same.network?我想要 ec2 1 中的容器 1 访问 ec2 2 上的容器 2。如何使用 same.network 绑定不同机器上的 2 个容器?

(I assume the two instances are in the same VPC. If not, the answer will be more complicated.) (我假设这两个实例在同一个 VPC 中。如果不是,答案会更复杂。)

You need to know the IPs of the two EC2 instances to reference them from each other.您需要知道两个 EC2 实例的 IP 才能相互引用它们。 You can give them static IPs, or you can use Route 53 and an Infrastructure as Code tool (eg CloudFormation or Terraform) to bind the assigned IP to an internal DNS name (eg container-one.internal ).您可以为它们提供 static IP,或者您可以使用 Route 53 和基础架构即代码工具(例如 CloudFormation 或 Terraform)将分配的 IP 绑定到内部 DNS 名称(例如container-one.internal )。

Then, when you want to call one container from the other, just send an HTTP request and handle it on the receiving side.然后,当你想从另一个容器调用一个容器时,只需发送一个 HTTP 请求并在接收端处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM