---
title: "Confidently Deploy Containers in this AWS ECS Tutorial"
description: "Learn to confidently deploy and manage Docker containers in this AWS ECS tutorial along with the difference between AWS Fargate and EKS!"
canonical: "https://adamtheautomator.com/aws-ecs-tutorial/"
---

# Confidently Deploy Containers in this AWS ECS Tutorial

> Learn to confidently deploy and manage Docker containers in this AWS ECS tutorial along with the difference between AWS Fargate and EKS!

Source: https://adamtheautomator.com/aws-ecs-tutorial/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Confidently Deploy Containers in this AWS ECS Tutorial](https://adamtheautomator.com/wp-content/uploads/2022/10/Confidently-Deploy-Containers-in-this-AWS-ECS-Tutorial.jpg)

# Confidently Deploy Containers in this AWS ECS Tutorial

[![](https://secure.gravatar.com/avatar/c33e3be4c378d7366050eb6c4da41523f27a6c41e9e9d8332a085f42adcdc8e3?s=192&d=mm&r=g)Inam Ul Haq](https://adamtheautomator.com/author/inam-ul-haq/)3 November 20227 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[AWS](/tag/aws/)[AWS ECS](/tag/aws-ecs/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Creating a Repository in this AWS ECS Tutorial](#creating-a-repository-in-this-aws-ecs-tutorial)
*   [Pushing a Docker Image to ECR](#pushing-a-docker-image-to-ecr)
*   [Creating an ECS Cluster](#creating-an-ecs-cluster)
*   [Creating a Task Definition](#creating-a-task-definition)
*   [Running the Docker Container in ECS](#running-the-docker-container-in-ecs)
*   [Conclusion](#conclusion)

Are you looking to create a big-scale application but are worried about how you’ll manage it? Maintaining such a big-scale application is a big task. How do you think you’ll tackle this undertaking? What will happen if your server goes down?

Perhaps it’s time you consider moving your Docker containers to Amazon Elastic Container Service (ECS). Don’t be scared. This AWS ECS tutorial teaches you how to deploy your Docker application and never worry about scaling and downtime again!

ECS becomes easier once the AWS networking, IAM, and container pieces click together. If you want a structured learning path alongside this tutorial, [compare AWS and container courses on Udemy](https://trk.udemy.com/c/1454808/3193860/39854) before you buy.

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have the following:

*   An active AWS account – Register a [free-tier account](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all) first if you don’t have one.
    
*   Docker and [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) must be installed on your computer – This tutorial uses Docker 20.10.20 and AWS CLI 2.8.3 on [Ubuntu 20.04](https://adamtheautomator.com/install-ubuntu/).
    

Related:[How To Install And Use AWS CLI On Windows](https://adamtheautomator.com/install-aws-cli-on-windows/)

*   An existing Docker image or a [_Dockerfile_](https://docs.docker.com/engine/reference/builder/) for building one – This AWS ECS tutorial uses a Docker image containing a web application serving a static website.

Related: [How to Set up an Apache Docker Container](https://adamtheautomator.com/apache-docker/)

## Creating a Repository in this AWS ECS Tutorial

To start with this AWS ECS tutorial, you first need to create a repository in Amazon Elastic Container Repository (ECR), where you’ll push your Docker image.

1\. Open your favorite web browser and log in to [AWS Management Console](https://console.aws.amazon.com/console/home).

2\. At the search bar, type in Elastic Container Service or **ECS**, and click **Elastic Container Service** from the results. Doing so will redirect you to the ECS page.

![Searching Elastic Container Service in the search bar](https://adamtheautomator.com/wp-content/uploads/2022/10/image-706.png)

Accessing the ECS Dashboard

3\. Click on the **Repositories** sidebar menu.

![Opening Repositories](https://adamtheautomator.com/wp-content/uploads/2022/10/image-707.png)

Opening Repositories

4\. On the **Repositories** page, click on the **Create repository** button. Doing so will redirect you to a form to fill out and create the repository.

![Initiating the repository creation.](https://adamtheautomator.com/wp-content/uploads/2022/10/image-708.png)

Initiating the repository creation

5\. In the **Create Repository** form, select the visibility of the new repository — **Public** or **Private.** Select **Public** in this example so that the repository will be accessible everywhere.

![Setting the visibility of the repository](https://adamtheautomator.com/wp-content/uploads/2022/10/image-709.png)

Setting the visibility of the repository

6\. Next, enter the name of the new repository. Ensure that you follow the naming rules below.

![Naming the Repository](https://adamtheautomator.com/wp-content/uploads/2022/10/image-710.png)

Naming the Repository

7\. Lastly, scroll to the bottom of the page and click the **Create repository** button.

![Creating Repository](https://adamtheautomator.com/wp-content/uploads/2022/10/image-711.png)

Creating the Repository

## Pushing a Docker Image to ECR

Now that you’ve created the repository, the next step in this AWS ECS tutorial is to push the Docker image file to the repository.

1\. Click the new repository named **ecr-tutorial** to open it.

![Open the repository](https://adamtheautomator.com/wp-content/uploads/2022/10/image-712.png)

Opening the repository

2\. Click on the **View push commands** button to get the commands you must run on your computer to push an image to the repository.

> _As of this writing, AWS CLI is the only way to push Docker images to ECR._

![Viewing the push commands button](https://adamtheautomator.com/wp-content/uploads/2022/10/image-713.png)

Viewing the push commands

3\. Next, you should see a window similar to the one below. Copy the commands for later and click **Close.**

![Viewing the Docker image push commands](https://adamtheautomator.com/wp-content/uploads/2022/10/image-714.png)

Viewing the Docker image push commands

4\. Now that you have the commands to push the Docker image to the repository, start by running the first saved command to authenticate your Docker client to the registry.

```powershell
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/n7a3i1h9
```

Wait to see a **Login Succeeded** message to confirm a successful login.

![Authenticating your Docker client to ECR](https://adamtheautomator.com/wp-content/uploads/2022/10/image-715.png)

Authenticating your Docker client to ECR

5\. Next, execute the following command to build a new Docker image named `ecr-tutorial` for this AWS ECS tutorial.

> _Ensure that the Dockerfile file is inside the same directory. If you already have a Docker image with the same name as your repository in AWS ECS, skip this step._

This command builds an image with a website that displays the words “_AWS ECS Tutorial @ AdamTheAutomator.com”_ listening on HTTP port 80.

```powershell
docker build -t ecr-tutorial .
```

![Building the container](https://adamtheautomator.com/wp-content/uploads/2022/10/image-716.png)

Building the container

6\. Now that you’ve built the Docker image, run the following command to `tag` the image with your repository prefix. This step enables you to push the image to your ECR repository later.

```powershell
docker tag ecr-tutorial:latest public.ecr.aws/n7a3i1h9/ecr-tutorial:latest
```

7\. Finally, run the following command to push the Docker image to the repository.

```powershell
docker push public.ecr.aws/n7a3i1h9/ecr-tutorial:latest
```

The push process can last several minutes depending on your image size, internet speed, and system capacity. This example took less than one minute to complete.

![Pushing the Docker image to ECR](https://adamtheautomator.com/wp-content/uploads/2022/10/image-717.png)

Pushing the Docker image to ECR

8\. Lastly, open your repository in ECR and confirm that you can see the image you pushed. Click on **Copy URI** and paste it into Notepad or any note-taking program for later use.

![Copying the image URI](https://adamtheautomator.com/wp-content/uploads/2022/10/image-718.png)

Copying the image URI

## Creating an ECS Cluster

You’ve successfully created a repository and pushed an image. But before deploying this image in a container, you must create the ECS cluster. Creating a cluster will create the required resources in the background.

Follow the below steps to create a new cluster in this AWS ECS tutorial.

1\. Navigate to the [ECS page](https://console.aws.amazon.com/ecs).

2\. Click **Clusters** from the sidebar menu under the Amazon ECS heading.

![Open the Clusters page](https://adamtheautomator.com/wp-content/uploads/2022/10/image-719.png)

Open the Clusters page

3\. Click on **Create Cluster** to create a new cluster.

![Initiating the Cluster creation process](https://adamtheautomator.com/wp-content/uploads/2022/10/image-720.png)

Initiating the cluster creation process

4\. Select the **EC2 Linux + Networking** template, and click on the select button.

> _The **EC2 Linux + Networking** cluster is preferable for long-term production-level projects, while **Networking only** is suitable for small testing environments and short-term projects._

![Selecting the ECS cluster template](https://adamtheautomator.com/wp-content/uploads/2022/10/image-721.png)

Selecting the ECS cluster template

5\. Next, enter the **Cluster name**. This example uses _**learn-ecs-cluster**_ as the cluster name.

![Specify the cluster name](https://adamtheautomator.com/wp-content/uploads/2022/10/image-722.png)

Specifying the cluster name

6\. On the **Provisioning Model**, you have two options. The **On-Demand Instance** is the _pay-as-you-go_ model, while the **Spot** model charges you a monthly fixed price. In this tutorial, choose the **On-Demand Instanced** model.

![Select the provisioning model](https://adamtheautomator.com/wp-content/uploads/2022/10/image-723.png)

Selecting the provisioning model

7\. On the **EC2 instance type**, select the EC2 size that the ECS will provision. This example chooses the **t2.micro** instance type.

> _Refer to [Amazon EC2 Instance Types](https://aws.amazon.com/ec2/instance-types/) for the list of available EC2 instance types._

![Select the EC2 instance type](https://adamtheautomator.com/wp-content/uploads/2022/10/image-724.png)

Selecting the EC2 instance type

8\. Under **Networking**, specify the **VPC**, **Subnets**, and **Security Group** for this cluster’s EC2 instance. Also, select **Enable** next to the **Auto assign public IP** so that the cluster assigns a public IP address to your instance.

> _Ensure that the Security group you choose has rules that allow access to your application’s required port(s)._

![Configure the instance networking](https://adamtheautomator.com/wp-content/uploads/2022/10/image-725.png)

Configuring the instance networking

9\. Now you’ve filled in all the cluster configurations, click on the **Create** button to create the cluster.

![Creating the Cluster](https://adamtheautomator.com/wp-content/uploads/2022/10/image-726.png)

Creating the cluster

10\. Once the cluster creation finishes, you will see a similar output to the one below. Click on the **View Cluster** button.

![ECS Cluster creation result](https://adamtheautomator.com/wp-content/uploads/2022/10/image-727.png)

Confirming the ECS cluster creation result

## Creating a Task Definition

Your next step in this AWS ECS tutorial is creating the Task definition. The task definition specifies the container information, such as the quantity of the containers running in the task and what resources the container will consume.

> _In essence, creating a task definition in AWS ECS is like creating a Docker Compose (`docker-compose.yml`) file on your computer._

1\. Click on the Task definition from the sidebar menu and the **Create new Task Definition** button.

![Click Create new Task Definition](https://adamtheautomator.com/wp-content/uploads/2022/10/image-728.png)

Initiating creating a new Task Definition

2\. Select **EC2** under the **Select launch type compatibility** heading because the cluster template uses the EC2 template. Click **Next step.**

![Selecting the task launch type compatibility](https://adamtheautomator.com/wp-content/uploads/2022/10/image-729.png)

Selecting the task launch type compatibility

3\. Enter the **Task definition name**. The name can be anything you want, but choose a name that is descriptive of its purpose.

![Naming the Task definition](https://adamtheautomator.com/wp-content/uploads/2022/10/image-730.png)

Naming the Task Definition

4\. Under **Task size**, enter the adequate **Task memory** and **Task CPU** values based on your assessment of the task load. In this example, the values are **100** (MiB) and **1 vcpu** (Unit), which are enough to run a basic web server.

![Configure the task size](https://adamtheautomator.com/wp-content/uploads/2022/10/image-731.png)

Configuring the task size

5\. Now, click **Add container** to create the container definitions, which include the image URI, port mapping, and the container name, among others.

![Click Add container](https://adamtheautomator.com/wp-content/uploads/2022/10/image-732.png)

Initiating adding a new container

6\. Next, enter the following information:

*   **Container name** – This example uses the name **learn-ecs-container**.
*   **Image** – This Docker image URI you copied earlier. This example will fetch the image at _**public.ecr.aws/n7a3i1h9/ecr-tutorial:latest.**_
*   **Port mappings** – The host port and container port mapping. This example container will be accessible through the EC2 host’s port 8080, and the web server listens to port 80.

After configuring the container, click **Add**.

![ Setup the container](https://adamtheautomator.com/wp-content/uploads/2022/10/image-733.png)

Setting up the container’s standard information

The new container definition appears on the list.

![Container definitions list](https://adamtheautomator.com/wp-content/uploads/2022/10/image-734.png)

Verifying the new container exists

7\. Lastly, scroll down to the bottom of the page and click **Create**.

![Create the task definition ](https://adamtheautomator.com/wp-content/uploads/2022/10/image-735.png)

Creating the Task Definition

You will see a confirmation banner indicating the task definition creation was successful.

![Task definition creation result](https://adamtheautomator.com/wp-content/uploads/2022/10/image-736.png)

Verifying the task definition creation is succesful

## Running the Docker Container in ECS

The next step in this AWS ECS tutorial is to test whether your image and container deployment works. To do so, you must run a new task using the task definition you created.

1\. Click **Clusters** → **cluster name (learn-ecs-cluster)**.

![Open the ECS cluster](https://adamtheautomator.com/wp-content/uploads/2022/10/image-737.png)

Opening the ECS cluster

2\. Click the **Tasks** tab and click on the **Run New Task** button.

![Running new Task](https://adamtheautomator.com/wp-content/uploads/2022/10/image-738.png)

Running a new task

3\. On the **Run Task** page, select **EC2** as the **Launch type**. Assuming that you only have one **Task Definition** and **Cluster**, those values will auto-populate. If not, make sure to select the correct ones.

![Configuring the task](https://adamtheautomator.com/wp-content/uploads/2022/10/image-739.png)

Configuring the task

4\. Scroll to the bottom of the page and click the **Run Task** button.

![Running the Task](https://adamtheautomator.com/wp-content/uploads/2022/10/image-740.png)

Running the task

5\. Once the task runs, click the **ECS Instances** tab and the **ECS Instance** link.

![Open the ECS instance](https://adamtheautomator.com/wp-content/uploads/2022/10/image-741.png)

Opening the ECS instance

6\. Next, copy the Public IPv4 address or Public IPv4 DNS. Either of these two addresses is what you need to access the Docker web application container.

![Copy the ECS instance Public IP or DNS](https://adamtheautomator.com/wp-content/uploads/2022/10/image-742.png)

Copying the ECS instance public IP or DNS

7\. Open a browser window and navigate the ECS instance IP address or DNS. Remember to append the host’s port number that you specified in the container’s port mapping.

```powershell
Copy the ECS instance Public IP or DNS
```

![Accessing the Docker container web server via the public IP address](https://adamtheautomator.com/wp-content/uploads/2022/10/image-743.png)

Accessing the Docker container web server via the public IP address

```powershell
# Public DNS
HTTP://ec2-3-19-68-252.us-east-2.compute.amazonaws.com:8080
```

![Accessing the Docker container web server via the public DNS name](https://adamtheautomator.com/wp-content/uploads/2022/10/image-743.png)

Accessing the Docker container web server via the public DNS name

## Conclusion

This AWS ECS tutorial taught you how to create a repository and push a Docker image. After which, you created a new cluster and deployed the Docker container running a web server.

Did this tutorial spark your interest? Do you think you’ll use AWS ECS in your future project?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Faws-ecs-tutorial%2F&text=Confidently%20Deploy%20Containers%20in%20this%20AWS%20ECS%20Tutorial)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Faws-ecs-tutorial%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Faws-ecs-tutorial%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/05/HMaster-Your-Data-with-AWS-Quicksight.jpg)

### [Make Data-Driven Decisions with AWS QuickSight Analytics](/aws-quicksight/)

Struggling to make sense of your data? Discover how AWS QuickSight transforms data into actionable insights for smarter decision-making.

![](https://adamtheautomator.com/wp-content/uploads/2023/11/aws-network-access-analyzer-2.jpg)

### [Getting Started with AWS Network Access Analyzer](/aws-network-access-analyzer/)

Unlock the power of AWS Network Access Analyzer. Master network security with step-by-step guidance in this tutorial today!

![](https://adamtheautomator.com/wp-content/uploads/2023/11/ngrok-remote.jpg)

### [Hosting an Ngrok Remote Web App on AWS](/ngrok-remote/)

Learn how to run the Ngrok remote web application on AWS with the FastAPI Python endpoint in Linux through this ATA Learning tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
