When a task run in ECS does it docker run in Foreground or in detached mode. Is it possible to set these options in the task definition?
They run in detached mode. This is evident if you login to your container instance and inspect the docker run command used to launch your task.
An example from my ECS instance:
docker run \
[parts not shown]
--detach=true \
1234455666.dkr.ecr.us-east-1.amazonaws.com/a03c-fffffecr-fffffos4q \
python3 app.py
Notice the --detach=true option.
I'm not aware of any way to change this option. When ECS starts, there is no terminal tty to run in the attached mode anyway.