This tutorial will guide you through the process of deploying and running Docker containers on Amazon Elastic Container Service (ECS) with AWS Fargate using AWS CloudFormation stacks. To accomplish this, we’ll be creating Elastic Container Registry (ECR) and multiple CloudFormation stacks for groups of resources on the cloud, including VPC, subnets, load balancers, CloudWatch, ECS Cluster, container tasks, and services.

Here are the steps we’ll follow:

  1. Containerize a simple REST API application by building a Docker image.
  2. Use AWS CLI to create a repository on Amazon Elastic Container Registry (Docker Registry).
  3. Push the Docker image to the repository on Amazon ECR.
  4. Define and run a CloudFormation stack to create VPC and all network components.
  5. Define and run a CloudFormation stack to create IAM roles.
  6. Define and run a CloudFormation stack to create ECS Cluster, Load balancer, CloudWatch Log Group, and Security Groups.
  7. Define and run a CloudFormation stack to deploy the Docker application, including creating a task for the container, a service to schedule the task, a load balancer target group for container services, and a load balancer listener rule for container service.

Upon completing this tutorial, you will be able to create ECS Fargate infrastructure using CloudFormation code, and deploy and execute Docker containers on ECS.