2

I am doing some experimenting with ECS Fargate. I came across a situation where I have three containers running on the same Task. Is there any way I would be able to ssh into to these three containers ?

After some digging I found it's possible if I had only one container, here. But nowhere I could find how to do this when you have multiple containers running in the same task. I am wondering if this is possible at all. Maybe Fargate is not for me, I have to go with ECS EC2.

Note: I have to manually run some php scripts now and then, thats why I need to get in to these containers.

spark
  • 41
  • 3
  • That works for multiple containers as well. There are some minimalistic init/systemd replacement available for example https://ahmet.im/blog/minimal-init-process-for-containers/ – petrch Sep 20 '20 at 13:43

2 Answers2

1

I couldn't find any other way to solve the issue, since I can't have three containers in same task exposing 22, I had to update port used for ssh from 22 to 2222, 2223 (any other port) while building other two containers.

RUN sed -i 's/#Port 22/Port 2222/g' /etc/ssh/sshd_config
spark
  • 41
  • 3
0

Note: I have to manually run some php scripts now and then, thats why I need to get in to these containers.

In this context my suggestion would be to use ECS scheduled cron tasks to execute these scripts if you need to run them on a regular schedule.

If you run them more adhoc instead of on a calendar schedule the I'd recommend pulling the script out into its own container that can be run using the ECS RunTask API

Don't be afraid to run more containers. In general the ideal usage of containers is one process or job per container. If you have multiple types of jobs then run multiple types of containers.

You would also ideally have one task definition for each container type. So maybe:

  1. website container -> website task definition -> launch task definition as an ECS service
  2. api container -> api task definition -> launch task definition as its own ECS service
  3. PHP script container -> script task definition -> use ECS RunTask to execute that script task (or schedule it to automatically execute periodically on a cron schedule)

I don't know what your specific workloads look like but hopefully this serves as an example that if you have three things they would ideally be three different containers, three task defs, and three separate ECS services/tasks

nathanpeck
  • 4,608
  • 1
  • 20
  • 18