Deploy a Docker Container on AWS

Containerize a web app and deploy it to AWS ECS Fargate with a public URL.

Introduction

30 Second Summary

Every app you use on your phone or computer runs somewhere on a server. Companies package these apps into containers so they can run reliably anywhere, from a developer's laptop to a cloud data center.

In this project, you will build a Docker container from scratch and deploy it to AWS using Amazon ECS on AWS Fargate. By the end, your container will be live on the internet with a public IP address anyone can visit.

What You'll Build

A simple web application containerized with Docker and deployed to AWS using Amazon ECS on Fargate, accessible from any browser via a public IP address.

By the end of this project, you'll have:

  • A custom Dockerfile and container image built and tested on your local machine.
  • An Amazon ECR repository storing your container image in the cloud.
  • A running ECS Fargate service with a public IP serving your web app to the internet.
  • Secret Mission: Add an Application Load Balancer for production-ready traffic distribution and health checks.

Are there any prerequisites?

No prior experience with Docker or AWS is required. This project includes full setup instructions for every tool you need, including Docker Desktop and the AWS CLI.

Set Up Your Tools

To deploy a container to AWS, you need two tools working together on your machine. Docker builds and runs your container locally, and the AWS CLI lets you push that container to the cloud.

In this step, you will verify both tools are installed and configure the AWS CLI with your credentials.

In this step, get ready to:
  • Confirm Docker Desktop is installed and running.
  • Confirm the AWS CLI is installed and configured.
  • Set up an AWS account with an IAM user for CLI access.
Install Docker Desktop

Docker Desktop is the application that lets you build and run containers on your computer. It runs a lightweight Linux virtual machine behind the scenes so containers work seamlessly on macOS and Windows.

  • Press Cmd+Space (macOS) or the Windows key (Windows) to open your search bar.
  • Type Terminal and press Enter to open it.
  • Check if Docker is installed by running this command:
docker --version

✔️ I see a version number

Docker is installed and ready. Make sure Docker Desktop is running by checking for the whale icon in your menu bar (macOS) or system tray (Windows).

If the whale icon is not visible, open Docker Desktop using your search bar.

ⓧ Command not found

You need to install Docker Desktop. Follow these steps:

  • Open https://docs.docker.com/desktop/setup/install/mac-install/ in your browser (macOS) or https://docs.docker.com/desktop/setup/install/windows-install/ (Windows).
  • Download the installer for your system (Apple chip or Intel chip on macOS).
  • On macOS, double-click Docker.dmg and drag the Docker icon to your Applications folder.
  • On Windows, run the downloaded installer and follow the on-screen prompts.
  • Open Docker Desktop from your Applications folder (macOS) or Start menu (Windows).
  • Accept the license agreement when prompted.
  • Wait for Docker Desktop to finish starting. You will see the whale icon appear in your menu bar or system tray.
  • Run docker --version again to confirm installation.

Still not working?

Make sure Docker Desktop is fully started before running the version check. The whale icon should be static, not animated.

help me troubleshoot Docker Desktop installation

Install and configure the AWS CLI

The AWS CLI is a command-line tool that lets you manage AWS services from your terminal. You will use it to authenticate with AWS and push your Docker image to the cloud.

  • Check if the AWS CLI is installed by running this command:
aws --version

✔️ I see a version number starting with aws-cli/2

The AWS CLI v2 is installed and ready. You can move on to configuring your credentials below.

ⓧ Command not found

You need to install the AWS CLI v2. Follow these steps:

  • On macOS, download the installer from https://awscli.amazonaws.com/AWSCLIV2.pkg in your browser.
  • On Windows, download the installer from https://awscli.amazonaws.com/AWSCLIV2.msi in your browser.
  • Run the downloaded file and follow the on-screen instructions.
  • On macOS, the installer will ask you to choose an install location. Keep the default and click through each step.
  • Close and reopen your terminal after installation completes.
  • Run aws --version again to confirm. You should see output starting with aws-cli/2.

Still seeing command not found?

Make sure you closed and reopened your terminal after installation. The installer adds aws to your PATH, but existing terminal sessions do not pick up the change automatically.

help me troubleshoot AWS CLI installation

Now configure the AWS CLI with your credentials. The aws configure command will prompt you for four values.

  • Run the configuration command:
aws configure

What will this command ask me?

The aws configure command prompts you for four values, one at a time:

  • AWS Access Key ID - paste the Access Key ID from your IAM user.
  • AWS Secret Access Key - paste the Secret Access Key from your IAM user.
  • Default region name - enter us-east-1.
  • Default output format - enter json.
  • Enter each value when prompted, pressing Enter after each one.

Where do I find my Access Key ID and Secret Access Key?

These credentials come from your IAM user in the AWS Console. If you have not created an IAM user yet, follow the next substep to set one up.

If you already have an IAM user with access keys, paste your existing credentials into the prompts.

Create an AWS account (if needed)

If you do not have an AWS account or IAM user yet, follow the steps below to set them up. Skip this substep if you already ran aws configure successfully with valid credentials.

  • Open https://aws.amazon.com in your browser.
  • Click Create an AWS Account in the top right corner.
  • Follow the sign-up prompts to create your account. You will need an email address, a payment method, and a phone number for verification.

What about costs?

New AWS accounts receive Free Tier credits that cover the services used in this project. The entire tutorial costs less than $0.01 if you complete it within an hour and delete your resources afterwards.

Once your account is ready, create an IAM user with the permissions needed for this project:

  • Sign in to the AWS Console at https://console.aws.amazon.com.
  • Search for IAM in the top search bar and select it.
  • Click Users in the left sidebar.
  • Click Create user.
  • Enter a username (e.g. admin-user) and click Next.
  • Select Attach policies directly.
  • Search for AdministratorAccess and check the box next to it.
  • Click Next, then Create user.

Now generate access keys for your new user:

  • Click on your newly created user's name.
  • Select the Security credentials tab.
  • Scroll down to Access keys and click Create access key.
  • Select Command Line Interface (CLI) as the use case.
  • Check the confirmation box and click Next, then Create access key.
  • Copy your Access Key ID and Secret Access Key somewhere safe. You will not be able to see the secret key again after leaving this page.

Save your credentials securely

Never share your Secret Access Key or commit it to source control. Store it in a password manager or a secure note. You will only see it once during creation.

  • Return to your terminal and run aws configure to enter the Access Key ID, Secret Access Key, region us-east-1, and output format json.

Seeing an error when running AWS commands?

Double-check that you pasted the Access Key ID and Secret Access Key correctly. Extra spaces or missing characters will cause authentication failures.

help me fix my AWS CLI configuration

Your environment is ready. Next up, you will build your first Docker image and test it locally before pushing it to the cloud.

Build Your Docker Image

Your development environment is set up with Docker and the AWS CLI. Now it's time to create the application you'll deploy to the cloud.

Every container starts with two things: the application code and a Dockerfile that tells Docker how to package it. You'll create both, build a container image, and test it on your own machine before pushing it anywhere.

In this step, get ready to:
  • Create your project files (an HTML page and a Dockerfile).
  • Build a Docker image from your Dockerfile.
  • Test the container locally to confirm it works before deploying.
Create your project files

You need a project folder to hold your application code and its Docker configuration.

  • Move to your Desktop and create your project folder by running these commands:
cd ~/Desktop
mkdir my-web-app
cd my-web-app
  • Confirm you're inside the new folder by running:
pwd

You should see a path ending in /my-web-app.

Seeing 'directory already exists'?

If you already have a folder called my-web-app on your Desktop from a previous attempt, delete it first with rm -rf ~/Desktop/my-web-app and re-run the commands above.

Help me fix my project directory setup.

Now you'll create the two files your container needs. The first is index.html which is the web page your container will serve.

  • Create a new file called index.html in your my-web-app folder using any text editor (TextEdit, Notepad, nano, VS Code) and paste in the following content:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Container App</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        .container {
            text-align: center;
            padding: 2rem;
        }
        h1 {
            font-size: 2.5rem;
            margin-bottom: 0.5rem;
        }
        p {
            font-size: 1.2rem;
            opacity: 0.9;
        }
        .badge {
            display: inline-block;
            background: rgba(255,255,255,0.2);
            padding: 0.5rem 1rem;
            border-radius: 20px;
            margin-top: 1rem;
            font-size: 0.9rem;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Hello from AWS ECS Fargate!</h1>
        <p>This container is running on serverless infrastructure.</p>
        <div class="badge">Deployed with Docker + Amazon ECS</div>
    </div>
</body>
</html>

What does this HTML do?

This is a simple web page with a purple gradient background, a heading, a subtitle, and a small badge. It's styled with inline CSS so there's no need for extra files.

The content itself doesn't matter for learning Docker deployment. What matters is that you have a real web page to verify your container is serving correctly once it's live.

  • Save index.html.

✔️ Awesome, I've got everything!

Great. Make sure you've saved the file before moving on.

ⓧ I'd like to double check the full code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Container App</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        .container {
            text-align: center;
            padding: 2rem;
        }
        h1 {
            font-size: 2.5rem;
            margin-bottom: 0.5rem;
        }
        p {
            font-size: 1.2rem;
            opacity: 0.9;
        }
        .badge {
            display: inline-block;
            background: rgba(255,255,255,0.2);
            padding: 0.5rem 1rem;
            border-radius: 20px;
            margin-top: 1rem;
            font-size: 0.9rem;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Hello from AWS ECS Fargate!</h1>
        <p>This container is running on serverless infrastructure.</p>
        <div class="badge">Deployed with Docker + Amazon ECS</div>
    </div>
</body>
</html>

Next, you need a Dockerfile. This is the recipe that tells Docker how to build your container image.

  • Create a new file called Dockerfile (no file extension) in your my-web-app folder and paste in the following content:
FROM --platform=linux/amd64 nginx:latest
WORKDIR /usr/share/nginx/html
COPY index.html index.html

What does this Dockerfile do?

  • FROM --platform=linux/amd64 nginx:latest starts from the official Nginx web server image. The --platform=linux/amd64 flag ensures the image works on AWS Fargate, even if you're building on an Apple Silicon Mac.
  • WORKDIR /usr/share/nginx/html sets the working directory to where Nginx looks for web files.
  • COPY index.html index.html copies your HTML file into the image so Nginx can serve it.
  • Save Dockerfile.
  • Confirm both files exist by running:
ls

You should see Dockerfile and index.html in the output.

Don't see both files?

Make sure you saved each file inside the my-web-app folder on your Desktop. If you saved them elsewhere, move them into the folder or recreate them.

Also confirm the Dockerfile has no extension. Some editors may add .txt automatically. The file should be named exactly Dockerfile with a capital D.

Help me fix my project file setup.

✔️ Awesome, I've got everything!

Great. Make sure both files are saved before moving on.

ⓧ I'd like to double check the full code

FROM --platform=linux/amd64 nginx:latest
WORKDIR /usr/share/nginx/html
COPY index.html index.html
Build and test locally

With your files in place, you can now build a Docker image. An image is a snapshot of your application and everything it needs to run.

  • Build your Docker image by running this command:
docker build -t my-web-app .

What does this command do?

  • docker build reads your Dockerfile and builds an image from it.
  • -t my-web-app tags (names) the image my-web-app so you can reference it later.
  • . tells Docker to look for the Dockerfile in the current directory.

You should see Docker downloading the Nginx base image and building your custom image. The last line will say something like Successfully tagged my-web-app:latest.

Build failing?

Make sure Docker Desktop is running. Check for the whale icon in your menu bar (macOS) or system tray (Windows).

If you see a "no such file or directory" error, confirm you're inside the my-web-app folder by running pwd. The folder must contain both Dockerfile and index.html.

Help me fix my Docker build error.

Now you'll run the image as a container on your machine to test that everything works before deploying to AWS.

  • Start your container by running this command:
docker run -d -p 80:80 my-web-app

What does this command do?

  • docker run creates and starts a new container from your image.
  • -d runs the container in detached mode (in the background).
  • -p 80:80 maps port 80 on your machine to port 80 inside the container, so you can access the web server from your browser.
  • Open your web browser and go to http://localhost.

You should see your custom web page with a purple gradient background, the heading "Hello from AWS ECS Fargate!" and the badge text.

Page not loading?

If you see "connection refused" or a blank page, check that port 80 isn't already in use by another application. Run docker ps to confirm your container is running.

On macOS, the built-in Apache server can sometimes claim port 80. If so, stop it with sudo apachectl stop then re-run the docker run command.

Help me fix my Docker container not loading in the browser.

Your container is working locally. Before moving on, stop the running container so it doesn't keep port 80 occupied.

  • Stop the container by running this command:
docker stop $(docker ps -q --filter ancestor=my-web-app)

You should see a container ID printed in the terminal, confirming the container has stopped.

What does this command do?

The inner command docker ps -q --filter ancestor=my-web-app finds the container ID of any running container built from the my-web-app image. The outer docker stop command stops that container.

Your Docker image is built and tested. Next, you'll push this image to Amazon ECR so that AWS can access it for deployment.

Push Your Image to Amazon ECR

Your Docker image works locally, but AWS services can't pull it from your laptop. To deploy your container on ECS Fargate, the image needs to live in a cloud registry that AWS can access.

Amazon ECR (Elastic Container Registry) is AWS's container image storage service. In this step, you'll create a repository in ECR and push your image to it so ECS can use it later.

In this step, get ready to:
  • Create a private ECR repository.
  • Authenticate Docker to your ECR registry.
  • Tag and push your image to ECR.
Create an ECR repository

An ECR repository is like a folder that holds different versions of your container image. You'll create one specifically for your web app.

  • In the AWS Management Console, click the search bar at the top.
  • Type ECR and select Elastic Container Registry from the results.
  • Click Get started or Create repository.
  • Keep the visibility set to Private.
  • For Repository name, enter my-web-app.
  • Leave all other settings as defaults and click Create repository.

You should see your new my-web-app repository listed on the ECR Repositories page.

Why a private repository?

A private repository means only your AWS account can pull images from it. This keeps your container images secure and prevents anyone else from accessing them.

Don't see the Create repository button?

Make sure you're in the Private registry tab, not the Public one. Also confirm your region is set to us-east-1 in the top-right corner of the console.

Help me troubleshoot the ECR console.

Authenticate and push your image

Docker doesn't know how to talk to ECR by default. You need to authenticate first, then tag your image with the ECR address before pushing it.

  • Click on your my-web-app repository name to open it.
  • Click View push commands in the top-right area of the repository page.

Your account ID is pre-filled here

The push commands dialog shows all four commands pre-filled with your AWS account ID. You can copy commands directly from here if you prefer. Your 12-digit account ID is the number before .dkr.ecr in each command.

  • Switch back to your terminal.
  • Authenticate Docker to your ECR registry by running this command:
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin [[AWS_ACCOUNT_ID="your 12-digit AWS account ID"]].dkr.ecr.us-east-1.amazonaws.com

You should see Login Succeeded in your terminal output.

What does this command do?

This command has two parts joined by a pipe (|).

  • aws ecr get-login-password asks AWS for a temporary authentication token.
  • docker login uses that token to authenticate Docker with your ECR registry.

Getting an authentication error?

  • Make sure you replaced the account ID placeholder with your actual 12-digit AWS account ID.
  • Confirm your AWS CLI is configured with valid credentials by running aws sts get-caller-identity.
  • Check that Docker Desktop is running (look for the whale icon in your menu bar).

Help me fix my ECR authentication error.

  • Tag your local image with the ECR repository address by running:
docker tag my-web-app:latest [[AWS_ACCOUNT_ID="your 12-digit AWS account ID"]].dkr.ecr.us-east-1.amazonaws.com/my-web-app:latest

Why do I need to tag the image?

Docker needs to know WHERE to push the image. Tagging adds the full ECR address to your image name, so Docker knows the destination when you push.

  • Push the tagged image to ECR by running:
docker push [[AWS_ACCOUNT_ID="your 12-digit AWS account ID"]].dkr.ecr.us-east-1.amazonaws.com/my-web-app:latest

This may take a minute depending on your internet speed. You should see progress bars as each layer uploads, followed by a latest: digest: sha256:... confirmation when complete.

  • Switch back to the ECR console in your browser.
  • Click on your my-web-app repository.
  • You should see an image with the latest tag listed in the Images tab.

Image not appearing in ECR?

  • Make sure the push command completed without errors in your terminal.
  • Confirm you used the same account ID in both the tag and push commands.
  • Refresh the ECR console page. Sometimes the UI takes a moment to update.

Help me troubleshoot my Docker push to ECR.

Your container image is now stored in the cloud where any AWS service can access it. Next, you'll create an ECS cluster and deploy this image as a running service.

Deploy to ECS Fargate

Your container image is safely stored in Amazon ECR. Now it's time to deploy it to the cloud so anyone on the internet can access your web app.

Amazon ECS (Elastic Container Service) with AWS Fargate handles running your container without you needing to manage any servers. You'll create a cluster, define how your container should run, and launch it as a service.

In this step, get ready to:
  • Create an ECS cluster to group your container resources.
  • Create a task definition that tells ECS how to run your container.
  • Launch a service that runs your container and makes it publicly accessible.
Create an ECS cluster

A cluster is a logical grouping where your containers run. Think of it as a workspace that organizes your deployed services.

  • In the AWS Console, use the search bar at the top to search for ECS and select Elastic Container Service.
  • In the left navigation pane, click Clusters.
  • Click Create cluster.
  • Under Cluster configuration, for Cluster name, enter my-web-app-cluster.
  • Leave all other settings at their defaults. The console automatically associates AWS Fargate as the infrastructure provider.
  • Click Create.

Wait a few seconds for the cluster to finish creating. You should see your cluster listed with a status of Active.

What is a cluster?

An ECS cluster is a logical grouping of tasks, services, and infrastructure. It does not cost anything on its own. The Fargate capacity provider is automatically associated, meaning any containers you deploy here will run on serverless infrastructure managed by AWS.

Cluster creation failed?

Make sure you have the correct IAM permissions. Your IAM user needs at least AdministratorAccess (which you configured in Step 1).

Also confirm your region is set to us-east-1 in the top-right corner of the console.

help me troubleshoot my ECS cluster creation error

Create a task definition

A task definition is like a blueprint for your application. It tells ECS which container image to use, how much CPU and memory to allocate, and which ports to expose.

  • In the left navigation pane, click Task Definitions.
  • Click Create new Task Definition, then select Create new revision with JSON.

You'll see a JSON editor. You need to replace all the content in the editor with the task definition JSON below.

  • Clear the existing JSON in the editor and paste the following task definition:
{
    "family": "my-web-app-task",
    "networkMode": "awsvpc",
    "containerDefinitions": [
        {
            "name": "my-web-app",
            "image": "[[AWS_ACCOUNT_ID=\"your 12-digit AWS account ID\"]].dkr.ecr.us-east-1.amazonaws.com/my-web-app:latest",
            "portMappings": [
                {
                    "containerPort": 80,
                    "hostPort": 80,
                    "protocol": "tcp"
                }
            ],
            "essential": true
        }
    ],
    "requiresCompatibilities": [
        "FARGATE"
    ],
    "cpu": "256",
    "memory": "512"
}

What does this task definition do?

  • family names this task definition so ECS can track revisions of it.
  • networkMode: awsvpc gives the task its own network interface. This is required for Fargate.
  • image points to your container image in ECR (the one you pushed in the previous step).
  • portMappings exposes port 80 so web traffic can reach your nginx container.
  • cpu: 256 allocates 0.25 vCPU, and memory: 512 allocates 0.5 GB. This is the smallest Fargate configuration.

Find your account ID

Your 12-digit AWS account ID is the same one you used when pushing to ECR. You can also find it by clicking your username in the top-right corner of the AWS Console.

  • After pasting and updating the account ID, click Create.

You should see a success message confirming the task definition was created.

Seeing a JSON validation error?

Make sure you replaced the entire placeholder (including the angle brackets) with just your 12-digit account ID number.

Double-check there are no trailing commas or missing brackets in the JSON.

help me fix my ECS task definition JSON error

Create and run the service

A service keeps a specified number of tasks (containers) running at all times. If a container crashes, the service automatically launches a replacement.

  • In the left navigation pane, click Clusters.
  • Click on my-web-app-cluster to open it.
  • Select the Services tab, then click Create.

You'll see the Create Service page. Configure the following sections:

  • Under Environment, choose Launch type, then select FARGATE.
  • Under Deployment configuration, for Task definition family, choose my-web-app-task.
  • For Service name, enter my-web-app-service.
  • For Desired tasks, enter 1.

Now configure the networking so your container is accessible from the internet:

  • Expand the Networking section.
  • Under Security group, choose Create a new security group.
  • Enter a Security group name (e.g. my-web-app-sg) and a Description (e.g. Allow HTTP traffic).
  • Add an inbound rule: set Type to HTTP, Protocol to TCP, Port range to 80, and Source to Anywhere (0.0.0.0/0).
  • For Public IP, make sure it is turned on so the task gets a public IP address.

Why do we need a security group?

A security group acts as a virtual firewall for your container. By adding an inbound rule for port 80, you're telling AWS to allow web traffic to reach your nginx container from any IP address on the internet.

Without this rule, your container would run but nobody could connect to it.

  • Click Create to launch the service.

ECS will now start deploying your container. This takes about 1-2 minutes.

  • Wait for the Last status column in the Tasks tab to show Running. You may need to click the refresh button a few times.

Task stuck in PENDING or STOPPED?

If the task stays in PENDING, check that your VPC has a public subnet with an internet gateway. The default VPC includes this.

If the task shows STOPPED, click on the task and check the Stopped reason field. A common cause is an incorrect image URI in the task definition. Verify your account ID and region match your ECR repository.

help me debug my ECS Fargate task that won't start

Your container is now running on AWS Fargate. In the next step, you'll grab the public IP and confirm your web app is live on the internet.

Verify Your Deployment

Your service is deployed and running on ECS Fargate. Now comes the best part: seeing your container live on the public internet.

Every Fargate task with a public IP enabled gets a unique address that anyone in the world can reach. In this step, you'll locate that address in the ECS console and confirm your web app loads in a browser.

In this step, get ready to:
  • Find your container's public IP address in the ECS console.
  • Confirm your custom web page is live and accessible from any browser.
Find your container's public IP

Your running task has a public IP address assigned to it. You need to find this address in the ECS console to access your app from a browser.

  • In the AWS Console, navigate to Amazon ECS > Clusters.
  • Click on your cluster my-web-app-cluster.
  • Select the Services tab, then click on your service name.
  • Select the Tasks tab.
  • Click on the running task ID (the long alphanumeric string).
  • In the Configuration section, find the Public IP field.
  • Click Open address next to the Public IP, or copy the IP address and paste it into your browser's address bar.

What is this Public IP?

This is an IPv4 address assigned to your Fargate task's network interface. Because you enabled Assign public IP when creating the service, AWS gave your task a routable address that anyone on the internet can reach on port 80.

This IP is ephemeral. If your task restarts, it gets a new one. For a stable endpoint, you'd use a load balancer (that's what the Secret Mission covers).

Don't see a Public IP?

Make sure your task status shows RUNNING. If it says PROVISIONING or PENDING, wait 1-2 minutes for AWS to finish pulling your image and starting the container.

If the task shows STOPPED, click on it to see the stopped reason. Common causes include the image URI being incorrect or the task role missing permissions.

help me figure out why my ECS Fargate task doesn't have a public IP

Confirm your web app is live

When the Public IP loads in your browser, you should see the custom HTML page you built earlier.

  • Confirm you see a purple gradient background with the heading Hello from AWS ECS Fargate! displayed in white text.
  • Below the heading, you should see the text This container is running on serverless infrastructure. and a badge that says Deployed with Docker + Amazon ECS.

This is your Docker container, running on AWS infrastructure, accessible to anyone with the IP address. You just completed the full container deployment lifecycle: build, push, deploy, verify.

Page not loading or timing out?

If the browser spins without loading, your security group likely isn't allowing inbound traffic on port 80. Go back to your service's networking configuration and confirm the security group has an inbound rule for TCP port 80 from source 0.0.0.0/0.

If you see a connection refused error instead of a timeout, the container may have failed to start. Return to the ECS console and check the task's logs in the Logs tab for any nginx startup errors.

help me troubleshoot why my ECS Fargate container page isn't loading in the browser

Secret mission

Add an Application Load Balancer

Your container is live, but there's a problem. Every time your Fargate task restarts, it gets a new public IP address. In production, you need a stable endpoint that never changes. Add an Application Load Balancer in front of your service for production-ready traffic distribution and a permanent DNS name.

Clean Up Your Resources

Clean Up Your Resources

Decide whether to keep your resources running, pause them to come back later, or delete them entirely. Your ECS Fargate service charges approximately $0.004/hour while running, so leaving it active will incur ongoing costs.

Cost warning

Your Fargate task costs approximately $0.10/day (0.25 vCPU / 0.5 GB configuration). If you completed the Secret Mission, the Application Load Balancer incurs additional hourly charges.

If you are not planning to continue building on this project, choose Pause or Delete below to stop charges immediately.

Resources you used:

  • ECS cluster my-web-app-cluster with a running service and task (Fargate compute).
  • ECR repository my-web-app containing your Docker image.
  • Application Load Balancer and target group (if you completed the Secret Mission).
  • Local project files (index.html, Dockerfile, task-definition.json).

Keep everything running

No action needed. Choose this if you are still actively building on this project or exploring ECS further.

  • Your Fargate service continues running and serving traffic.
  • You will be charged approximately $0.10/day for the running task.
  • If you have an ALB, it incurs additional hourly charges.

Pause - I'll come back to this later

Shut down running tasks to stop Fargate charges while keeping your infrastructure intact.

  • In the ECS console, navigate to Clusters and select my-web-app-cluster.
  • Select the Services tab, then select your service.
  • Click Update and set Desired tasks to 0.
  • Click Update to confirm.
  • This stops all running tasks and eliminates Fargate charges. Your cluster, service definition, ECR image, and task definition remain in place for when you return.

Delete - I don't want to use this again

Remove all project resources to stop all charges and start fresh.

If you completed the Secret Mission, delete the ALB and target group first:

  • Open the EC2 console and choose Load Balancers in the navigation pane.
  • Select your load balancer, then choose Actions, Delete load balancer.
  • Enter confirm when prompted, then choose Delete.
  • In the navigation pane, under Load Balancing, choose Target Groups.
  • Select your target group, choose Actions, Delete.
  • Choose Yes, delete to confirm.

Delete the ECS service and cluster:

  • In the ECS console, navigate to Clusters and select my-web-app-cluster.
  • Select the Services tab, select your service, and click Delete.
  • Confirm the deletion.
  • Return to the cluster page and click Delete Cluster.
  • Enter delete me in the confirmation dialog and choose Delete.

Delete the ECR repository:

  • In the AWS console, navigate to Amazon ECR and choose Repositories.
  • Select the my-web-app repository and click Delete.
  • Confirm the deletion.

Delete local project files:

  • Remove your project folder from your Desktop by running:
cd ~/Desktop
rm -rf my-web-app

On Windows, use:

cd ~\Desktop
rmdir /s /q my-web-app

That's a Wrap!

That's a Wrap!

Nice work! You just deployed a Docker container to production-grade cloud infrastructure on AWS.

You've learned how to:

  • Built a custom Docker image from a Dockerfile and pushed it to Amazon ECR as your private container registry.
  • Deployed a running container to Amazon ECS using AWS Fargate for serverless compute, with a public IP accessible from any browser.
  • Managed the full container lifecycle: build, push, deploy, verify, and clean up.
  • Added an Application Load Balancer with health checks for production-ready traffic distribution.

Ready to quiz yourself?