NextJS standalone under ECS Container, can not use localhost or 127.0.0.1
05:08 09 Dec 2025

I have a frontend app running at port 3000.

......... 
USER nextjs

EXPOSE 3000

ENV PORT=3000
ENV HOSTNAME="0.0.0.0"

CMD ["node", "server.js"]

Inside the frontend's container, using netstat as you can see below, my NextJS service is listening at 172.31.45.194:3000 and not at 0.0.0.0:[PORT] as expected as all other services listed, i.e. backend at port 8000 and redis at port 6379

# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:20722         0.0.0.0:*               LISTEN      -                   
tcp        0      0 172.31.45.194:3000      0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::6379                 :::*                    LISTEN      -                   
# 

So, using curl http://localhost:3000 or http://127.0.0.1:3000 always fails. I need this to check the health of the container.

What seems to be wrong here? How to set up my NextJS standalone project or ECS container to work properly?

Note that all containers are under an Application Load Balancer.

I suspect that is the root of a problem where the ALB deregisters its IPs and restarts the service after a period of time, ~15-20 minutes.

docker next.js amazon-elb aws-fargate