简体   繁体   中英

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. 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?

(I assume the two instances are in the same VPC. If not, the answer will be more complicated.)

You need to know the IPs of the two EC2 instances to reference them from each other. 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 ).

Then, when you want to call one container from the other, just send an HTTP request and handle it on the receiving side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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