Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to open TTY #462

Closed
k2nr opened this issue Jul 28, 2016 · 24 comments
Closed

Add option to open TTY #462

k2nr opened this issue Jul 28, 2016 · 24 comments

Comments

@k2nr
Copy link

k2nr commented Jul 28, 2016

Right now there is no way to open TTY of a container that is launched by ECS agent. I need this option to run an interactive container inside our ECS cluster.
Specifically, I want to run rails console in our production cluster. Currently we do this by ssh'ing into the container instance and run docker run -it ... directly but this approach has several problems:

  • Now that ECS supports per-task IAM role, we also want an interactive container to be associated with the task IAM role
  • Our task definition is quite complex (volumes, network configurations, "sidekick containers" along with the main rails server container, etc...) so it is hard to emulate the TD configuration if we use docker run -it inside the container instance

So what we want to do with this tty option is: run ECS task with TTY, ssh into the container instance then docker attach to the container

@richardpen
Copy link

@k2nr Currently ECS doesn't support opening TTY for containers using task definition. But you can still launch your task in ECS, then ssh into your instance and use docker exec to attach to the container.

@clumsysnake
Copy link

@aaithal @richardpen do you know the roadmap for interactive tasks?

Had a thought that if there was an API call for createTask which would just call docker create, attaching and running via ssh would be way less hacky then what we have now, where you create a task with a process that never dies and then hope that you later remember to stop the container.

OR if there was a way of calling docker run commands as root directly on the container instance that we could be assured behaved the same as calling runTask from the API. I also use task IAM roles to fetch s3 config, and have task definition config that I want to be assured is the same between my interactive containers and app server containers. Maybe e.g. aws ecs run-local-container -it <task_definition>.

Of course the ideal scenario is just something like heroku run. Maybe you need your own ECS cli tool :)

@panga
Copy link

panga commented Sep 27, 2016

+1

@ryansch
Copy link

ryansch commented Sep 27, 2016

I have a working proof of concept for running rails console with an embedded tmux server. I'm working on a command line tool to launch it with RunTask, find the private ip of the instance to ssh to (through our bastion), ssh to that instance, and run a skinny docker container that just hosts tmux attach.

@jgangemi
Copy link

jgangemi commented Oct 6, 2016

are there any plans to support this? i want to gpg sign commits in the container and my builds fail with this error:

gpg: cannot open tty `/dev/tty': No such device or address

@mwarkentin
Copy link

@richardpen Another issue with doing it via docker exec is that doesn't run your ENTRYPOINT command. We're using it to set up some specific environment variables, which causes a problem.

@jgangemi
Copy link

jgangemi commented Feb 9, 2017

is there any potential forward motion on this? i'd still like to use the service but want the tty option.

@bithavoc
Copy link

You have the following labels per docker container running in your EC2 Container Instance:

"Labels": {
                "com.amazonaws.ecs.cluster": "testclusty",
                "com.amazonaws.ecs.container-name": "hello",
                "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:586687105316:task/019ee91b-3d29-4872-a7cf-9f730d7d607e",
                "com.amazonaws.ecs.task-definition-family": "testhello",
                "com.amazonaws.ecs.task-definition-version": "2"
            }

You just need to ssh to one of the instances where the task currently lives and do and replace the name of the container(in my case is hello) and run it as:

sudo docker exec -ti `docker ps -q -f 'label=com.amazonaws.ecs.container-name=hello'` /bin/sh

That opens a terminal inside the container, it works with a ruby on rails image as well:

sudo docker exec -ti `docker ps -q -f 'label=com.amazonaws.ecs.container-name=hello'` bundle exec rake db:migrate

@panga
Copy link

panga commented Feb 16, 2017

@bithavoc in real world we shouldn't have access to instance SSH, just the container :)

@bithavoc
Copy link

@panga true, what I posted is a walk-around I guess

@jgangemi
Copy link

i just took another look on the aws side of things and it doesn't appear this is an option in the task definition either, so i'm wondering if this is possible w/o that.

@bithavoc
Copy link

is not possible to tty @jgangemi , you can still do docker exec though

@ejholmes
Copy link
Contributor

ejholmes commented Mar 1, 2017

Just adding my +1 for ECS supporting something like this. We have a feature in Empire for running attached processes (just like heroku run), however, it has to go entirely through Docker in order to set the Tty and OpenStdin flags when creating the container. If you could specify these flags in the ContainerDefinition, then attaching to a container started by ECS would be possible, and we could just use the RunTask api (which we'd like to use, so that AWS Roles for ECS tasks will work within these containers).

@revmischa
Copy link

I would really like a way to run an ECS container with a TTY

@bithavoc
Copy link

Gave up on this, switched to Rancher and never looked back

@r1w1s1
Copy link

r1w1s1 commented Aug 28, 2017

+1

2 similar comments
@hSATAC
Copy link

hSATAC commented Oct 20, 2017

+1

@Tensho
Copy link

Tensho commented Nov 11, 2017

+1

@awsfanatic
Copy link

+1

1 similar comment
@kwent
Copy link

kwent commented Mar 21, 2018

+1

@sharanyad
Copy link
Contributor

You can now add tty and interactive options to your containers in your task definition. You can add these new options in the AWS Console now, and they'll be available in the AWS CLI and SDKs soon.

@jgangemi
Copy link

only took 2 plus years, but hey, better late then never!!!!

@ellenthsu
Copy link

Congrats team!

@leshik
Copy link

leshik commented Dec 7, 2019

@sharanyad so how one could attach from CLI to interactive tasks then?

fierlion pushed a commit to fierlion/amazon-ecs-agent that referenced this issue Feb 24, 2022
fierlion pushed a commit to fierlion/amazon-ecs-agent that referenced this issue Feb 24, 2022
fierlion pushed a commit to fierlion/amazon-ecs-agent that referenced this issue Mar 7, 2022
* Include amazon-ecs-volume-plugin and startup scripts in Debian Package (aws#450)

* add amazon-ecs-volume-plugin to rpm generic package (aws#462)

* Fix the issue that potentially curl target not present in bucket during release

* Update copyrights

Co-authored-by: Dennis Conrad <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests