How to enable tty and run interactive console with AWS ECS?

Deployed a Dockerized Rails Application on EC2 instance with AWS ECS service. I am using ecs-cli for deploying rails application which using docker-compose.yml file for deploying containers as services similar to docker-compose mode. For running interactive shell such as rails console for my app, I created one separate service with following definition:

version: '2'

    driver: local
    driver: local

    command: bundle exec rails c
    hostname: console
    mem_limit: 314572800
    env_file: ../.prod-env
    tty: true
    stdin_open: true
    ports: []
      - "app-logs:/home/app/log"
      - "app-tmp:/home/app/tmp"

But when I deploy the task with following command:

ecs-cli compose -f docker/docker-compose-console.yml --project-name app-console run console "bundle exec rails c"

The flags tty: true and stdin_open: true are ignored. Due to which the task running console boots up, changes to RUNNING state and then silently closes down with state 0.

Is there any way one can run interactive console session or tailed logs? What approaches are used to achieve similar behavior?

TL;DR: I want behavior similar to docker-compose run app rails c with AWS ECS service.

I also posted this question on Stackoverflow.

On ECS? No. They way it works is that each EC2 node runs an “agent” process, and periodically polls Amazon’s central server to find out what containers could be running. So there’s a couple of layers of disconnection between you running ecs-cli, a container being assigned somewhere, and it actually starting.

Of course, this being a standard Docker Compose file, nothing stops you from just running it locally (assuming you can aws ecr get-login so that you can pull the image, or build it yourself).

Set up an alternate logging driver, either to [log to Amazon’s CloudWatch service] or running your own ELK stack or something similar. (IME this is vastly better than logging to files and trying to manually review them.)

1 Like