Docker nginx container with php container task definition ECS communication


I currently have a normal docker compose file with a nginx service as well as a php service. The nginx on my osx local machine communicates with the php container just fine with the following config

server {
    listen 8080;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    client_max_body_size 256M;

    # Log files for Debug
    error_log  /dev/stdout info;
    access_log /dev/stdout;

    # Laravel web root directory
    root /var/www/html/public;
    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass localhost:9000; -> **this works with the "php" container name, host.docker.internal and 127.0.01.**
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;

    location ~ /\.(?!well-known).* {
        deny all;

My php image which is fpm exposes port 9000 and the container is called php.

the above all works well on my local. The problem is when using my cloudformation template on ECS. All launches well but the nginx conf is only able to find the php container on or localhost. It does not find the php container by container name or by host.docker.internal.

I would like that to work so i dont need to change my nginx conf for local and prod to suit the environment.

The php and nginx containers exist together in a vpc using fargate. they also lauch together as a service.
Not sure what i need to do for them to see each other on ECS.

Thank you