Rails container shuting down in AWS without reason. puma shutdown

Viewed 475

I have an application with Rails, Postgres, docker and docker-compose deploying on elastic beanstalks of AWS as multi-container. Also, I am pushing the image on the ECR of AWS. According with the instance logs the container is started, the db is created and migrated but without any reason the server is shutting down.

D, [2020-09-03T01:05:45.291305 #6] DEBUG -- :   [1m[35m (3.0ms)[0m  [1m[34mSELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC[0m
D, [2020-09-03T01:05:45.300744 #6] DEBUG -- :   [1m[36mActiveRecord::InternalMetadata Load (1.3ms)[0m  [1m[34mSELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2[0m  [["key", "environment"], ["LIMIT", 1]]
D, [2020-09-03T01:05:45.308267 #6] DEBUG -- :   [1m[35m (0.4ms)[0m  [1m[35mBEGIN[0m
D, [2020-09-03T01:05:45.309501 #6] DEBUG -- :   [1m[35m (0.5ms)[0m  [1m[35mCOMMIT[0m
D, [2020-09-03T01:05:45.310092 #6] DEBUG -- :   [1m[35m (0.5ms)[0m  [1m[34mSELECT pg_advisory_unlock(8461001017939384740)[0m
Postgrest database has been migrated!
=> Booting Puma
=> Rails 5.2.3 application starting in production 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 4.0.1 (ruby 2.6.3-p62), codename: 4 Fast 4 Furious
* Min threads: 5, max threads: 5
* Environment: production
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2020-09-03 02:09:56 +0000 ===
- Goodbye!
Exiting

Here I copy the files that I think are relevant:

Docker and docker-compose files

FROM ruby:2.6.3
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN gem install bundler -v '2.0.2'
RUN bundle install
COPY . /myapp
 
# Add a script to be executed every time the container starts.
# COPY ./entrypoints/docker-entrypoint.sh /usr/bin/
EXPOSE 3000
RUN chmod +x ./entrypoints/docker-entrypoint.sh
ENTRYPOINT ["./entrypoints/docker-entrypoint.sh"]
version: "3"
services:
  db:
    image: "postgres:latest"
    environment:
      - POSTGRES_PASSWORD=******
 
  server:
    restart: always
    build: .
    # Tag with the container registry to dev
    image: *********.dkr.ecr.us-west-1.amazonaws.com/backend-dev-erc:latest
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgrespassword
      - POSTGRES_HOST=db
      - POSTGRES_PORT=5432
 
    volumes:
      - .:/myapp
    ports:
      - "80:3000"
    depends_on:
      - db

./entrypoints/docker-entrypoint.sh file


#!/bin/bash
set -e

# If the database exists, migrate. Otherwise setup (create and migrate)
echo "Database already exists!" || bundle exec rake db:create db:migrate db:seed
bundle exec rake db:migrate 2>/dev/null || bundle exec rake db:create db:migrate db:seed
echo "Postgrest database has been migrated!"

# Remove a potentially pre-existing server.pid for Rails.
rm -f /myapp/tmp/pids/server.pid

# Then exec the container's main process (what's set as CMD in the Dockerfile).
rails server -b 0.0.0.0 -p 3000

Dockerrun.aws.json

{
  "AWSEBDockerrunVersion": 2,
  "containerDefinitions": [
    {
      "name": "server",
      "image": "********.dkr.ecr.us-west-1.amazonaws.com/backend-dev-erc:latest",
      "hostname": "server",
      "essential": true,
      "memory": 128,
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80
        }
      ]
    }
  ]
}
0 Answers
Related