How to Deploy a Docker app to ECS

Daniel Montoya
3 min readMar 18, 2020

Docker apps can be deployed to Amazon ECS by using Fargate or EC2.

For this tutorial, we are going to use EC2 as we want to self-manage the infrastructure using Amazon EC2 instances.

We will need:

  • An AWS account
  • A Docker image hosted in ECR or similar (we will use ECR for simplicity)

Steps required:

  1. Create an ECS Cluster
  2. Create a Task Definition
  3. Link the Task Definition to your Cluster
  4. Create a Service for your Task

Create an ECS Cluster

Configure Cluster:

Important: Container instance IAM role (Create new role):

Create a Task Definition

  1. Select launch type compatibility: EC2

2. Configure task and container definitions:

3. Task execution IAM role: Create New Role

4. Task Size: Optional

5. Add Container:

6. Click Create:

Link the Task Definition to your Cluster

  1. Go to Clusters > Click on “Your Cluster” > Tasks tab > Run new Task

2. Click Switch to launch type:

Create a Service for your Task

  1. Go to Clusters > Click on “Your Cluster” > Services tab > Create

2. Click Next Step until the review screen unless you have specific needs

Verify it worked

  1. SSH to your ECS instance (Go to EC2 Instances, copy IP address, use key pair)
  2. List Docker containers
docker ps

3. SSH into your Docker container

# Replace ecs-brighteyetea... with your container name:CONTAINER=ecs-brighteyetea-3-brighteyetea-79a3e4f8f48583941300docker exec -it $CONTAINER_NAME bash

Update the container in ECS

To make a change to your container, there are two steps required:

  1. Update the task definition
  2. Update the service

Update the task definition

  • Go to ECS > Task Definitions > Click on your task definition > Click the revision you wish to update > Click the “Create new revision” button on the top left
  • Make your changes, click “Create”

Update the service

  • Go to ECS > Clusters > Click on your cluster > Click on the service you wish to update > Click the “Update” button on the top right
  • Select your new revision (latest) and check the “Force new deployment” option

--

--