Communicate between docker containers in a docker network in AWS Beanstalk

I’m using AWS Beanstalk to deploy my project in ‘Multi-container Docker running on 64bit Amazon Linux’

Here’s my Dockerrun.aws.json as per documentation

{
    "AWSEBDockerrunVersion": 2,
    "containerDefinitions": [
      {
        "name": "child",
        "image": "nithinsgowda/child",
        "essential": true,
        "memory": 256,
        "portMappings": [
            {
              "hostPort": 9000,
              "containerPort": 9000
            }
        ],
        "links": [
          "master"
        ]
      },
      {
        "name": "master",
        "image": "nithinsgowda/master", 
        "essential": true,
        "memory": 512,
        "portMappings": [
          {
            "hostPort": 80,
            "containerPort": 8080
          }
        ],
        "links": [
          "child"
        ]
      }
    ]
  }

I can access my master container at port 80 from the public internet

Inside my master container I have an API call to be made to the child container
I have tried the below options :
None of them worked

fetch('http://child/api')
fetch('http://child:9000/api')
fetch('http://15.14.13.12:9000/api')   //My public DNS for the beanstalk application (Example)

If it was in a local docker-compose environment ‘http://child/api’ works perfectly fine. But this doesn’t work on Beanstalk.

How do I communicate with the child container from my master container ?

I have even tried bindIP attribute and assigned a local IP and tried accessing it with the local IP, it still doesn’t work

When looked into the server logs, docker ps was executed by the environment and both containers were up and running, port mappings were also displayed correct.

Source: Docker Questions

LEAVE A COMMENT