SSH into Containers
This guide shows how to SSH into running containers like Flightcontrol Web and Worker service types, and includes specific instructions for accessing Rails console in production.
We have a Flightcontrol CLI planned that will make this process much easier. Vote on the CLI feature here.
AWS CLI Setup
- Download and install the AWS CLI from https://aws.amazon.com/cli/.
- Download and install the Session Manager Plugin.
- Configure AWS CLI access, by adding user credentials.
SSH into a container
- Get the region of your service from the Flightcontrol dashboard
- Get the cluster ID of your service from the Flightcontrol dashboard:
- Navigate to the service’s AWS Resources tab in the Service Sidebar
- Find the “ECS Service” resource card
- Copy the short ID from the “ECS Service” card. Example:
rails-app-z880xp2
(Contact support if you need the ID for preview environments)
- Run this command, to list the servers running in your cluster:
aws ecs list-tasks --region <region> --cluster <cluster-id>
- Copy a task ID from the list. The task ID is the last piece for the ARN, like this
arn:aws:ecs:us-east-2:xxxxxx:task/<cluster-name>/<task id>
- Run this command which will get you shell access:
- If
bash
is installed in the image:aws ecs execute-command --region <region> --cluster <cluster-id> --container <cluster-id> --task <task-id> --interactive --command "/bin/bash"
- Else use
sh
:aws ecs execute-command --region <region> --cluster <cluster-id> --container <cluster-id> --task <task-id> --interactive --command "/bin/sh"
- If
- Repeat steps 3 - 5 every time you want shell access.
Rails Console
Once you have the region
, cluster-id
and task-id
, you can open a Rails console session directly by modifying the --command "/bin/bash"
to --command "/bin/bash -c 'source /root/.profile && bin/rails console'"
.
Full command:
aws ecs execute-command --region <region> --cluster <cluster-id> --container <cluster-id> --task <task-id> --interactive --command "/bin/bash -c 'source /root/.profile && bin/rails console'"
When using Rails console in production: Be cautious with destructive operations. Remember that long-running operations might impact application performance