Deploy Containerized Applications with ECS
Tags: beginners, devops, tutorial, productivity
Published: 2022-05-12 09:26:53


## DAY 31- Deploy Containerized Applications with ECS - Day Thirty One

[![Image tweet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jfjzxg64r7q0i8ra6b8t.png)![Image cover](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e96hapxc425p227i5afl.png)](https://twitter.com/intent/tweet?text=How%20to%20Deploy%20Containerized%20Applications%20with%20ECS%20%2C%20a%20blog%20by%20%40anuvindhs%0A%0Ahttps%3A%2F%2Fdev.to%2Faws-builders%2Fdeploy-containerized-applications-with-ecs-55dc%20)

[100 days of Cloud on GitHub](https://github.com/anuvindhs/100daysofcloud) - [Read On iCTPro.co.nz](https://ictpro.co.nz) - [Read on Dev.to](https://dev.to/anuvindhs)

------


## Get the app

Here Iam using a website with nginx server to deploy on a container with the help of ECR.
Let’s get the data

```git
git clone https://github.com/anuvindhs/CLOUD-is-AWSome.git
``` 

## Docker
**Building a docker file**
- Lets build our NGINX docker file for our website.

- once you have created the docker file inside the folder, copy-paste the below commands

```docker
FROM nginx:latest
COPY ./ /usr/share/nginx/html/
```
- I am using VScode, check below to understand the folder structure
![Image folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kq3am327gsgx1d7skxy3.png) 
## AWS Permissions

- Make sure you have programmatic access via AWS CLI 
- Full permissions to ECS & AmazonEC2ContainerRegistryFullAccess
  
##  ECR

**Create a repository**
- Goto ECR from AWS console and create a repository
- Create a ECR repo ,i have named mine `webapp-ecr-repo`

**Login to ECR**

if you open the repo, on the right-hand side you can see an option for view push commands.
![Image push commands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ayxvgvs8zxsn8lhlw17.png)
 
Now using AWS CLI login to ECR
```
aws ecr get-login-password --region xx-xxxxxx-xx| docker login --username AWS --password-stdin xxxxxxxxxx.dkr.ecr.xx-xxxxxx-xx.amazonaws.com
```
**Build the docker image**
```
docker build -t webapp-ecr-repo .
```

**Lets tag our image with repo name**
```
docker tag webapp-ecr-repo:latest xxxxxxxxx.dkr.ecr.xx-xxxxxx-xx.amazonaws.com/webapp-ecr-repo:latest
```
**Lets push the image to the repository**
```
docker push xxxxxxxxxx.dkr.ecr.xx-xxxxxxx-xx.amazonaws.com/webapp-ecr-repo:latest
```
if you are using PowerShell on windows please use windows commands to push the image to the repo.

![Image options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnf52260x3ghbsww5gob.png)
 

## ECS

### Create a cluster
- Goto ECS dashboard and click **Create Cluster**.
- select **EC2 Linux + Networking**
![Image ec2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gx0bme6o5zi36b768jb6.png)
 
- Enter **Cluster name** & **EC2 instance type** , am keeping it to t2.micro.
 ![Image clustername](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1g27zdv1vd5h3f0t2rh9.png)
 

- Select the default VPC and Subnets available.
- Also enable **Auto assign public IP**

![Image ip](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gw8pnga1f1siiersi1qx.png)
 
- you can use default Security group or create a new one or can attach a Security group which is already created.
- Now click **Create**
![Image create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6584w7s7a3msrj4dtfk6.png)
 

### Creating Task Definition

- Click on create Task Definition & then **select** EC2

![Image Taskdef](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p11ruekj5rd0vgkkscfz.png)
 
- I am naming mine as `Taskdef-webapp-ecr`
- Update **Task memory** to **128** and Task **CPU** to **1 vCPU**, then click **Add Container**
![Image container](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4c3hvfzrduu1ibcr4ed.png)
 
- Add a name, mine is `container-webapp-ecr`
- Copy your ECR repo URI from the repository and update that on the **image** coloumn
- Map your ports, here its 80:80 ,
- Now add, and create the Task definition.
![Image task def create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8an8newebeqc8vaw37m.png)
 
### Run the Task

 
- goto **Clusters**, select **Task** then click **Run New task**
![Image run a task](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tien5zp88qxly8qnti66.png)

- Select **EC2**
- Select out **Task Definition** we created.
- Select our **Cluster**
- leave everything default and click **Run Task**
![Image task defined](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gbo0nasmoyi4ykdenqvn.png)
 
Once the Task is created you will be able to see a _**Running Status**_
if you navigate to **external Link** you will be able to see the **live website**.




![Image external link](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ogd75m77rj6a4zx6phv.png)
 
 
Congratulations, now you have successfully configured a docker image which you have pushed to ECR and Deployed on a container with ECS.








----------

**✅Connect with me on [Twitter](https://twitter.com/intent/follow?ref_src=anuvindhs&screen_name=anuvindhs)
 🤝🏽Connect with me on [Linkedin](https://www.linkedin.com/in/anuvindhs)
🧑🏼‍🤝‍🧑🏻 Read more post on [dev.to](https://dev.to/anuvindhs) or  [iCTPro.co.nz](https://ictpro.co.nz)
💻 Connect with me on [GitHub](https://github.com/anuvindhs)**

----------
{% user anuvindhs %}