Elastic Beanstalk Container Randomly Dies

22 Views Asked by At

I recently started using Elastic Beanstalk to host my Node.JS Express containerized application to serve traffic as the backend of the my web application. It's a pretty standard Express app that's been containerized using a Dockerfile and a docker-compose.yaml file.

The issue that we've been facing is that, every so often, our container will randomly "die" and need to get restarted through the compose restart policy, which causes traffic to fail for that minute or two while the container is being restarted. We can't figure out what is going on. We switched over from GCP's Cloud Run to Elastic Beanstalk since we needed to switch to AWS for business reasons. It has been working great while online, but this random container disconnect is causing issues for our end users. I've included some of the code and logs below.

We've tried increasing our instance size (currently using t3.medium with 4GB RAM) to hopefully fix with no luck. Is the solution at this point to increase the instance desired count to 2 and pray they don't both die simultaneously? Would the load balancer handle that correctly?

Dockerfile

FROM node:14 as build

WORKDIR /usr/src/app
COPY . .

RUN yarn install --frozen-lockfile --production

FROM node:14-alpine as main

WORKDIR /usr/src/app
COPY --from=build /usr/src/app .

EXPOSE 5001

# Set the CMD to your handler
CMD [ "yarn", "docker:start" ]

docker-compose.yaml

version: "3.7"
services:
  backend-thanos-prod:
    container_name: backend-thanos-prod
    restart: always
    build:
      context: .
      dockerfile: Dockerfile
    env_file:
      - ./src/config/.prod.env
    ports:
      - '80:5001'
    volumes:
      - .:/usr/src/app

Logs from docker-events.log at the time of the downtime.

The main ones are just:

  1. 2024-03-02T08:44:00.365632320Z container die
  2. 2024-03-02T08:44:00.515722965Z network disconnect
  3. 2024-03-02T08:44:00.620752127Z network connect
  4. 2024-03-02T08:44:01.633985729Z container start

Docker-Events.log

0

There are 0 best solutions below