Skip to main content
TUTORIAL

Deploy Docker Containers on HAQM ECS

Introduction

Overview

HAQM Elastic Container Service (HAQM ECS) is the AWS service you use to run Docker applications on a scalable cluster. In this how-to guide, you will learn how to run a Docker-enabled sample application on an HAQM ECS cluster behind a load balancer, test the sample application, and delete your resources to avoid charges. This guide uses AWS Fargate, which has a ~$0.004 (less than half of a US cent) cost per hour when using the 0.25 vCPU / 0.5 GB configuration.

Implementation

Beginner

10 minutes

Cost will vary by region, and will be around $0.004 / hour of running the container

August 11, 2022

Set up your first run with HAQM ECS

The HAQM ECS first-run wizard will guide you through creating a cluster and launching a sample web application. In this step, you will enter the HAQM ECS console and launch the wizard.

1. Launch the first-run wizard

To launch the HAQM ECS first-run wizard, choose the Get started button. (If your layout looks different, disable the New ECS Experience toggle button at the top left of the console).

Missing alt text value

Create container and task definition

A task definition is like a blueprint for your application. In this step, you will specify a task definition so HAQM ECS knows which Docker image to use for containers, how many containers to use in the task, and the resource allocation for each container.

1. Select a task definition

In the Container definition field, select sample-app.

Missing alt text value

2. Review the default values

The task definition comes preloaded with default configuration values.

Review the default values and choose Next.

If you prefer to modify the configurations or would like to learn more, see Task definition parameters.

Missing alt text value

Define your service

Now that you have created a task definition, you will configure the HAQM ECS service. A service launches and maintains copies of the task definition in your cluster. For example, by running an application as a service, HAQM ECS will auto-recover any stopped tasks and maintain the number of copies you specify.

1. Review service options

Service options come preloaded with default configuration values.

  • Service name: The default sample-app-service is a web-based "Hello World" application provided by AWS. It is meant to run indefinitely; because it is running as a service, it will restart if the task becomes unhealthy or unexpectedly stops.

  • Number of desired tasks: Leave the default value of 1. This will create one copy of your task.

Missing alt text value

2. Review load balancing settings

Load balancing: You have the option to use a load balancer with your service. HAQM ECS can create an Elastic Load Balancing (ELB) load balancer to distribute the traffic across the container instances your task is launched on.

Select the Application Load Balancer option.

The default values for Load balancer listener port and Load balancer listener protocol are set up for the sample application. For more information on load balancing configuration, see Service load balancing.

Review your settings and choose Next. 

Missing alt text value

Configure your cluster

Your HAQM ECS tasks run on a cluster, which uses AWS Fargate to provide the compute engine so that you do not need to manage servers. In this step, you will configure the cluster.

1. Set cluster name

In the Cluster name field, enter sample-cluster and choose Next.

Missing alt text value

Launch and view your resources

In the previous steps, you configured your task definition (which is like an application blueprint), the HAQM ECS service (which launches and maintains copies of your task definitions), and your cluster. In this step, you will review, launch, and view the resources you create.

1. Review task definition

You have a final chance to review your task definition, task configuration, and cluster configuration before launching. Choose Create. 

Missing alt text value

2. View service status

You are on a Launch Status page that shows the status of your launch and describes each step of the process. After the launch is complete, choose View service. 

Missing alt text value

Open the sample application

In this step, you will verify that the sample application is up and running by pointing your browser to the load balancer DNS name.

1. View details about the application

On the sample-app-service page, select the Details tab and select the entry under Target Group Name. 

Missing alt text value

2. View target group details

On the Target groups page, select the target group name. 

Missing alt text value

3. Select the load balancer

In the Details section, choose the Load balancer link. 

Missing alt text value

4. Copy the DNS name of the application

In the Description tab, select the two page icon next to the load balancer DNS to copy the DNS name to your clipboard. 

Missing alt text value

5. View the sample application

Paste the name into a new browser window, and press Enter to view the sample application (in this case, a static webpage). 

Missing alt text value

Clean up

Throughout this guide, you've launched three resources: an HAQM ECS cluster, AWS Fargate to run your container, and a load balancer. In this step, you will clean up all your resources to avoid unwanted charges.

1. Select the cluster

Navigate back to the HAQM ECS console page and select the cluster name (sample-cluster).

Missing alt text value

2. Choose Delete Cluster

Choose Delete Cluster to delete the cluster.

Missing alt text value

3. Confirm cluster deletion

Enter delete me in the dialog box and choose Delete.

Missing alt text value

4. Monitor cluster deletion

You will now see the progress as all the resources created are deleted.

Missing alt text value

5. Cluster deletion complete

Once everything has been deleted, you will see the Deleted cluster sample-cluster successfully message in green. You have now completed this guide.

Missing alt text value

Congratulations

Congratulations! You have learned how to configure and deploy your Docker-enabled application to HAQM ECS, and how to delete resources that are no longer needed. HAQM ECS is a highly scalable, high performance container management service that supports Docker containers and allows you to easily run applications on a managed cluster of HAQM EC2 instances.