0

I'm trying to deploy a multiple docker container to Elastic Beanstalk. There is two containers, one for the supervisor+uwsgi+django application and one for the JavaScript frontend.

Using docker-compose it works fine locally

My docker-compose file:

version: '2'

services:
  frontend:
    image: node:latest
    working_dir: "/frontend"
    ports:
      - "3000:3000"
    volumes:
      - ./frontend:/frontend
      - static-content:/frontend/build
    command: bash -c "yarn install && yarn build"
  web:
    build: web/
    working_dir: "/app"
    volumes:
      - ./web/app:/app
      - static-content:/home/docker/volatile/static
    command: bash -c "pip3 install -r requirements.txt && python3 manage.py migrate && supervisord -n"
    ports:
      - "80:80"
      - "8000:8000"
    depends_on:
      - db
      - frontend
volumes:
  static-content:

The image for the nodejs is the oficial Docker one. For the "web" I use the following Dockerfile:

FROM ubuntu:16.04

# Install required packages and remove the apt packages cache when done.
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y \
    python3 \
    python3-dev \
    python3-setuptools \
    python3-pip \
    nginx \
    supervisor \
    sqlite3 && \
    pip3 install -U pip setuptools && \
   rm -rf /var/lib/apt/lists/*

# install uwsgi now because it takes a little while
RUN pip3 install uwsgi

# setup all the configfiles
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
COPY nginx-app.conf /etc/nginx/sites-available/default
COPY supervisor-app.conf /etc/supervisor/conf.d/

EXPOSE 80
EXPOSE 8000

However, AWS uses its own "compose" settings, defined in the dockerrun.aws.json, which has a different syntax, so I had to adapt it. First, I used the container-transform app to generate the file based on my docker-compose

Then I have to do some adjustment, i.e: The AWS file doesn't seem to have a "workdir" property, so I had to change it according

I also published my image to AWS Elastic Container Registry

The file became the following:

{
  "AWSEBDockerrunVersion": 2,
  "containerDefinitions": [
      {
          "command": [
              "bash",
              "-c",
              "yarn install --cwd /frontend && yarn build --cwd /frontend"
          ],
          "essential": true,
          "image": "node:latest",
          "memory": 128,
          "mountPoints": [
              {
                  "containerPath": "/frontend",
                  "sourceVolume": "_Frontend"
              },
              {
                  "containerPath": "/frontend/build",
                  "sourceVolume": "Static-Content"
              }
          ],
          "name": "frontend",
          "portMappings": [
              {
                  "containerPort": 3000,
                  "hostPort": 3000
              }
          ]
      },
      {
          "command": [
              "bash",
              "-c",
              "pip3 install -r /app/requirements.txt && supervisord -n"
          ],
          "essential": true,
          "image": "<my-ecr-image-path>",
          "memory": 128,
          "mountPoints": [
              {
                  "containerPath": "/app",
                  "sourceVolume": "_WebApp"
              },
              {
                  "containerPath": "/home/docker/volatile/static",
                  "sourceVolume": "Static-Content"
              },
              {
                "containerPath": "/var/log/supervisor",
                "sourceVolume": "_SupervisorLog"
              }
          ],
          "name": "web",
          "portMappings": [
              {
                  "containerPort": 80,
                  "hostPort": 80
              },
              {
                  "containerPort": 8000,
                  "hostPort": 8000
              }
          ],
          "links": [
            "frontend"
          ]
      }
  ],
  "family": "",
  "volumes": [
      {
          "host": {
              "sourcePath": "/var/app/current/frontend"
          },
          "name": "_Frontend"
      },
      {
          "host": {
              "sourcePath": "static-content"
          },
          "name": "Static-Content"
      },
      {
          "host": {
              "sourcePath": "/var/app/current/web/app"
          },
          "name": "_WebApp"
      },
      {
        "host": {
            "sourcePath": "/var/log/supervisor"
        },
        "name": "_SupervisorLog"
    }
  ]
}

But then after deploy I see it on the logs:

> -------------------------------------                                                                                                                                                                                              /var/log/containers/frontend-xxxxxx-stdouterr.log                     
> 
> -------------------------------------                                                                                                                                                                                              yarn install v1.3.2                                                   
> [1/4] Resolving packages...                                           
> [2/4] Fetching packages...                                            
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> info There appears to be trouble with your network connection.
> Retrying...                                                           
> error An unexpected error occurred:
> "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.179.0.tgz:
> ESOCKETTIMEDOUT".

I have tried to increase timeout for yarn... but the error still happen

I also can't even execute bash on the container (it gets stuck forever) or any other command (i.e: trying to reproduce the yarn issue)

And the _SupervisorLog doesn't seem to be mapping according, the folder is empty and I can't understand exactly what is happening or reproduce correctly the error

If I try to go to the url sometimes I get a Bad Gateway, sometimes I don't even get that. If I try to go to the path where it should load the "frontend" I get a "forbidden" error. Just to clarify, this is working fine when I run the containers locally with docker-compose.

I have started using Docker recently, so feel free to point any other issue you might find on my files.

dfranca
  • 135
  • 8
  • The subnets you're deploying your ec2 instances to, do they have a NAT gateway and a route to it attached? Does the role for your beanstalk instances have access to the ECS registry? – strongjz Jan 13 '18 at 22:23
  • the beanstalk role has full access to ECS registry. I don't know how to check about the EC2 having a NAT gateway and a route, the EC2 instance were created in using the default provided by Elastic beanstalk when creating a instance. – dfranca Jan 13 '18 at 23:05
  • 1
    Check the environment settings, it should have the subnets that your deploying instances to, Then check the routes tables have a route to a NAT gateway or a Internet Gateway. If they neither, then you can;t reach the Internet. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-create-wizard.html#environments-create-wizard-instances – strongjz Jan 13 '18 at 23:12
  • The thing is that I can reach the internet. If I just ssh to my instance and ping or curl to any website it works. – dfranca Jan 15 '18 at 10:43
  • Try setting up the busybox container and test DNS resolution, to rule out if it is your docker container or a host issue. `docker run -it --rm busybox` https://hub.docker.com/_/busybox/ – strongjz Jan 15 '18 at 15:21

0 Answers0