How to make AWS containers communicate

by CorayThan   Last Updated January 02, 2018 23:00 PM

I'm creating a single page application where the static frontend assets are served by an nginx docker container, and the java backend is also running in a docker container. I tied the two containers together with Docker Compose and got it working locally.

So I went to put it up in AWS using Elastic Beanstalk and found out EBS doesn't support Docker Compose. So instead I created a file, which is apparently how you define a multi-container Docker setup for EBS. I got that to create my containers in EBS, and the nginx container does serve my static front end content.

Unfortunately, I can't figure out how to get the nginx container to forward requests to my backend java api container. I can't even seem to find any documentation on how to do this with EBS.

Here's my nginx configuration. Specifically I think proxy_pass http://api:5000 needs to be changed.

server {
    listen       4000;
    server_name  localhost;

    root   /usr/share/nginx/html;
    index  index.html index.htm;

    # Matches any request with a file extension. Adds cache headers.
    location ~ .*\..* {
        try_files $uri =404;
        expires 1y;
        access_log off;
        add_header Cache-Control "public";

    # Matches api requests and redirects to the api server's port.
    location /api {
        proxy_pass http://api:5000;

    # Any route that doesn't have a file extension. This helps react router route page urls using index.html.
    location / {
        try_files $uri $uri/ /index.html;


This is the error nginx logs when it tries to forward the request:

2018/01/02 22:03:01 [error] 5#5: *22 connect() failed (111: Connection refused) while connecting to upstream, client:, server: localhost, request: "POST /api/auth/login HTTP/1.1", upstream: "", host: "", referrer: ""

And my file:

  "AWSEBDockerrunVersion": "2",
  "containerDefinitions": [
      "name": "proxy",
      "image": "",
      "essential": true,
      "memory": 64,
      "portMappings": [
          "hostPort": 80,
          "containerPort": 4000
      "links": [
      "name": "api",
      "image": "",
      "essential": true,
      "memory": 128

And you probably don't need it, but here's the docker-compose.yml I'm translating into the

version: '3'


      context: ./ui
      dockerfile: Dockerfile
    image: ""
      - "80:4000"
      - api
    restart: always

    image: ""
    restart: always

Related Questions

Multiple docker containers elastic beanstalk

Updated April 30, 2015 21:00 PM

Deploy a Docker environment on Elastic Beanstalk

Updated August 03, 2015 14:00 PM

AWS ElasticBeanstalk: container keeps restarting

Updated September 23, 2015 20:00 PM