In this step, we will containerize our Next.js Frontend application and push the Docker image to Amazon Elastic Container Registry (ECR). This image will later be used by ECS Fargate to launch the application.
We use a multi-stage Dockerfile optimized for Bun (a fast JavaScript runtime) and Next.js. This configuration reduces the final image size and improves security.
oven/bun:1.1.26
Run the following command in your project root to build the image. We tag it as band-up-frontend.
docker build -t band-up-frontend .
The build process will install dependencies using bun install and compile the project.

Once the build is complete, verify that the image exists locally.
docker image ls
You should see band-up-frontend with the latest tag.

Test Locally: You can try running the container locally to ensure it starts up correctly before pushing to AWS.
docker run -p 3000:3000 band-up-frontend:latest

Now we need to upload this image to AWS.
Step 1: Create Repository
Private.band-up-frontend.Step 2: Push Image
Use the AWS CLI to authenticate and push the image. Replace [AWS_ACCOUNT_ID] and [REGION] with your details.
Login to ECR:
aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin [AWS_ACCOUNT_ID].dkr.ecr.ap-southeast-1.amazonaws.com
Tag the Image:
docker tag band-up-frontend:latest [AWS_ACCOUNT_ID].dkr.ecr.ap-southeast-1.amazonaws.com/band-up-frontend:latest
Push the Image:
docker push [AWS_ACCOUNT_ID].dkr.ecr.ap-southeast-1.amazonaws.com/band-up-frontend:latest
Once the push is complete, your image is hosted on AWS ECR and ready for deployment.