Docker Community Forums

Share and learn in the Docker community.

Rails API, Docker, ECS Fargate | CannotStartContainerError: API error (400)

(Geekaynarayan) #1

New to Docker, but I was able to dockerize a rails api, run it locally on Mac and everything works fine. After that I deployed to AWS ECS Fargate and the service starts fine (logs below)

=> Booting Puma
=> Rails 5.2.1 application starting in production
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.0 (ruby 2.4.1-p111), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: production
* Listening on tcp://
Use Ctrl-C to stop

Then I call the API in Postman and as expected it returns a db not found message…
“status”: 500,
“error”: “Internal Server Error”,
“exception”: “#<ActiveRecord::NoDatabaseError: FATAL: database “railsapi_db” does not exist\n>”,
“traces”: {
“Application Trace”: [],
“Framework Trace”: [

So far so good. Then I create a task definition in ECS with a command override to run a rake command to create the db…

Rails db:create

The task fails with the following error message.

|Status reason|CannotStartContainerError: API error (400): OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"rails db:setup\": executable file not found in $PATH": unknown|
|Command|["rails db:setup"]|

No logs are generated by Fargate…

I’m sure many have deployed rails APIs to Fargate and wondering how they execute commands like rails db:setup or create migrate etc?

.Any thoughts / suggestions?