<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: leotoras</title>
    <description>The latest articles on Forem by leotoras (@leotoras).</description>
    <link>https://forem.com/leotoras</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1087304%2F167c98a8-e346-46e1-979f-d7bd05c0e8a6.JPG</url>
      <title>Forem: leotoras</title>
      <link>https://forem.com/leotoras</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/leotoras"/>
    <language>en</language>
    <item>
      <title>AWS EKS - Let's play with it</title>
      <dc:creator>leotoras</dc:creator>
      <pubDate>Wed, 14 Jun 2023 21:03:08 +0000</pubDate>
      <link>https://forem.com/leotoras/aws-eks-lets-play-with-it-4l7e</link>
      <guid>https://forem.com/leotoras/aws-eks-lets-play-with-it-4l7e</guid>
      <description>&lt;p&gt;Lets start talking about AWS EKS service, what it is, what it does and so on.&lt;/p&gt;

&lt;p&gt;For this article, lets assume that you already have a basic knowledge about containers, basic knowledge about Kubernetes and how they work.&lt;/p&gt;

&lt;p&gt;So, EKS states for Elastic Kubernetes Service and it is a managed service, that means you don't need to worry about infrastructure, where you can deploy your Kubernetes environment and without needing to install anything to have your control plane and nodes up and running. The only thing you need is a few clicks with the proper configuration.&lt;/p&gt;

&lt;p&gt;The AWS EKS service is fully integrated with other AWS services like ECR that makes things easier to deploy your container images, load balancer to distribute the traffic to your pods, IAM to secure the environment among others.&lt;/p&gt;

&lt;p&gt;We will not go deeper in theory about Kubernetes, so lets start having our hands dirty to better understand this service !&lt;/p&gt;

&lt;p&gt;To interact with Kubernetes and our EKS service, we will need 2 tools that will help us. They are the eksctl (command line tool to interact with EKS service and use CloudFormation behind the scenes to create your cluster) and kubectl (to interact with Kubernetes services).&lt;/p&gt;

&lt;p&gt;I'm using an EC2 instance with Amazon Linux 2023 as my environment, but you can choose any environment you feel comfortable. &lt;/p&gt;

&lt;p&gt;You can install eksctl issue the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ARCH=amd64
PLATFORM=$(uname -s)_$ARCH
curl -sLO "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$PLATFORM.tar.gz"
tar -xzf eksctl_$PLATFORM.tar.gz -C /tmp &amp;amp;&amp;amp; rm eksctl_$PLATFORM.tar.gz
sudo mv /tmp/eksctl /usr/local/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make sure eksctl is installed successfully, issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eksctl version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should receive an output with the eksctl version like that:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F25xgzrk59gwpbnbkyq01.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F25xgzrk59gwpbnbkyq01.PNG" alt="Image description" width="800" height="124"&gt;&lt;/a&gt;&lt;br&gt;
Now, lets install kubectl. To do that, just issue the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.27.1/2023-04-19/bin/linux/amd64/kubectl
chmod +x ./kubectl
mkdir -p $HOME/bin &amp;amp;&amp;amp; cp ./kubectl $HOME/bin/kubectl &amp;amp;&amp;amp; export PATH=$HOME/bin:$PATH
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can verify if the installation is fine with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl version --short --client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should return the kubectl version info like that:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2gquajfzb5gc4l11r1bt.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2gquajfzb5gc4l11r1bt.PNG" alt="Image description" width="800" height="120"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"Don't worry about the message saying that the flag --short has been deprecated."&lt;/p&gt;

&lt;p&gt;Great, now we have everything we need to start working with our EKS service. The very first thing we need to start working is a cluster. When we create a cluster, we 2 node types that we can work with, they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fargate: this type of compute capacity is also know as serverless because you dont have EC2 instances to manage. You simply put your pods to run and nothing else.&lt;/li&gt;
&lt;li&gt;EC2 instances: this type uses EC2 instances to have your pods running, so you need to choose the instance family, instance size, number of instances and so on. In this case, the instances are customized for EKS service. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, let's create our cluster. To make things simple, lets use Fargate compute mode and default options. We can do that using the eksctl, issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eksctl create cluster --name devto-article-eks-cluster \
--region us-east-1 \
--fargate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will take a few minutes and when it finishes, you will see an output like that:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj88ml75r8ki7bjryz2un.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj88ml75r8ki7bjryz2un.PNG" alt="Image description" width="800" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that our cluster is live, we can try some kubectl commands to interact with. Lets try a command to list the nodes, so just type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get nodes -o wide
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will list the nodes like that:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa43z76i9pkhr5fp7t8mo.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa43z76i9pkhr5fp7t8mo.PNG" alt="Image description" width="800" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you create a Kubernetes cluster, it created some internal pods that are used by Kubernetes to work properly. What about to see what are those services ? To do that, issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pods -A -o wide
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output should like following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvk4b1ffw7uy4147c931c.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvk4b1ffw7uy4147c931c.PNG" alt="Image description" width="800" height="73"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Those are coredns pods, that act as a DNS server for Kuberntes pods. We will not go deeper in Kubernetes sctructure, so that information is enought for now. Lets keep focusing on EKS service.&lt;/p&gt;

&lt;p&gt;Great, now we can create our Kubernetes deployment that will pull our container image from a repository. We can run our pod with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl run devto-article-pod --image &amp;lt;your_account_id&amp;gt;.dkr.ecr.us-east-1.amazonaws.com/my-eks-container-repo:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"Remember to replace the subnet ids by your subnets".&lt;/p&gt;

&lt;p&gt;Lets check if out pod is running as expected. Type the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get po
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output shows our container running in a pod as expected:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7iqulvk5lwn4iczlspi0.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7iqulvk5lwn4iczlspi0.PNG" alt="Image description" width="800" height="137"&gt;&lt;/a&gt;&lt;br&gt;
Now, the final part, make sure our pod has a container doing what is expected, show the welcome message ! Lets check that, we just need to login into the container which is running our app and execute a curl to check the message. Go ahead and execute the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl exec -it devto-article-pod -- /bin/bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Amaaaaazing news !!! Our pod is running the container as expected:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzmq2mhn9839hfqgo54y.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzmq2mhn9839hfqgo54y.PNG" alt="Image description" width="800" height="176"&gt;&lt;/a&gt;&lt;br&gt;
After some commands, we are finally done with our mission to have a pod application running on a EKS cluster as required. &lt;/p&gt;

&lt;p&gt;You did a great job. Thank you so much for follow me in this article and see you in the next.&lt;/p&gt;

&lt;p&gt;sources:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html"&gt;https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://eksctl.io/usage/creating-and-managing-clusters/"&gt;https://eksctl.io/usage/creating-and-managing-clusters/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/sample-deployment.html"&gt;https://docs.aws.amazon.com/eks/latest/userguide/sample-deployment.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html"&gt;https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>eks</category>
      <category>awsek</category>
    </item>
    <item>
      <title>AWS ECS - Let's play with it</title>
      <dc:creator>leotoras</dc:creator>
      <pubDate>Wed, 14 Jun 2023 17:57:00 +0000</pubDate>
      <link>https://forem.com/leotoras/aws-ecs-lets-play-with-it-4l53</link>
      <guid>https://forem.com/leotoras/aws-ecs-lets-play-with-it-4l53</guid>
      <description>&lt;p&gt;Lets start talking about AWS ECS service, what it is, what it does and so on.&lt;/p&gt;

&lt;p&gt;For this article, lets assume that you already have a basic knowledge about containers and how they work (if not, please take a look at &lt;a href="https://aws.amazon.com/docker"&gt;&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;So, ECS states for Elastic Container Service and it is a container orchestration service where you can launch your container applications in an easily manner. It makes activities like deploy, manage and scale the applications much more easier.&lt;br&gt;
As it is a service, you really don't need to worry or concern about hardware infrastructure, which is totally managed by AWS (as said, it is a fully managed service). In other words, if you want to run your containerized application on AWS without worry about infrastructure management, ECS is the right option.&lt;/p&gt;

&lt;p&gt;To make things easier than before ECS is also fully integrated with AWS ECR (Elastic Container Registry), which is another AWS fully managed AWS service to push your container images. If you are used with Docker Hub, don't worry, it works as well !&lt;/p&gt;

&lt;p&gt;We are ready to start, so first things first. Now it is time to visit the AWS ECR service :-)&lt;/p&gt;

&lt;p&gt;When you work with ECS, you have 3 options for computing capacity. They are EC2 instances, Fargate and ECS Anywhere (using on premise resources). Lets explain a little bit about each one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;EC2 instances: this type uses EC2 instances to have your services and tasks running, so you need to choose the instance family, instance size, number of instances and so on. In thi case, the instances are customized for ECS service and have the ecs-agent running on top of them.&lt;/li&gt;
&lt;li&gt;Fargate: this type of compute capacity is also know as serverless because you don't have EC2 instances to manage. You simply put your services and tasks to run and  nothing else.&lt;/li&gt;
&lt;li&gt;ECS Anywhere: this type of compute is the ability to register on premise servers to your ECS cluster (we will not touch on this inn this article !).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are in doubt on what type of compute capacity you use, you can take a look at this document: &lt;a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/common_use_cases.html"&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To make things simple, lets work with Fargate compute mode to run our containers. To start with that, first of all we need an ECS cluster, so lets create one. We have a lot of option to create our cluster, using AWS console, using CLI, using AWS SDK and other IaC tools like CloudFormation and Terraform for example. In our case, lets make it simple and use CLI.&lt;br&gt;
Simply issue this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ecs create-cluster --cluster-name devto-ecs-cluster --capacity-providers FARGATE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should have an output like that:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9pc5t0pag8dl9kj1uk47.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9pc5t0pag8dl9kj1uk47.PNG" alt="Image description" width="800" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make sure the cluster is there, you can list it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ecs list-clusters
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You are able to see out cluster:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnie533qpoqvkqaxmmedk.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnie533qpoqvkqaxmmedk.PNG" alt="Image description" width="800" height="92"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, our cluster is up and running, cool ! The next step is to create a task definition for our containers, but what is that ? Let me explain. &lt;/p&gt;

&lt;p&gt;Task Definition is a text file in JSON format that describes the containers and their parameters that will be part of the application. The parameters include CPU, memory, image name, IAM role, logging information and much more. You can visit this &lt;a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_AWSCLI_Fargate.html#ECS_AWSCLI_Fargate_register_task_definition"&gt;&lt;/a&gt; to take a deeper look on task definitions.&lt;/p&gt;

&lt;p&gt;That said, lets create out task definition. You can use any text editor, in my case I use vi to create a JSON file called devto-task-definition, like following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "containerDefinitions": [
        {
            "name": "devto-article-container",
            "image": "&amp;lt;your_account_id&amp;gt;.dkr.ecr.us-east-1.amazonaws.com/my-ecs-container-repo",
            "cpu": 0,
            "portMappings": [
                {
                    "name": "devto-article-container-80-tcp",
                    "containerPort": 80,
                    "hostPort": 80,
                    "protocol": "tcp",
                    "appProtocol": "http"
                }
            ],
            "essential": true,
            "environment": [],
            "environmentFiles": [],
            "mountPoints": [],
            "volumesFrom": [],
            "ulimits": [],
            "logConfiguration": {
                "logDriver": "awslogs",
                "options": {
                    "awslogs-create-group": "true",
                    "awslogs-group": "/ecs/devto-task-definition",
                    "awslogs-region": "us-east-1",
                    "awslogs-stream-prefix": "ecs"
                }
            }
        }
    ],
    "family": "devto-task-definition",
    "taskRoleArn": "arn:aws:iam::&amp;lt;your_account_id&amp;gt;:role/EcsTaskRole",
    "executionRoleArn": "arn:aws:iam::&amp;lt;your_account_id&amp;gt;:role/ecsTaskExecutionRole",
    "networkMode": "awsvpc",
    "volumes": [],
    "placementConstraints": [],
    "requiresCompatibilities": [
        "FARGATE"
    ],
    "cpu": "256",
    "memory": "512",
    "runtimePlatform": {
        "cpuArchitecture": "X86_64",
        "operatingSystemFamily": "LINUX"
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"Pay attention that I replaced my account id by the string . In your case, it should be your own account id."&lt;/p&gt;

&lt;p&gt;With the task definition file created, we need to register this task definition so ECS is able to reference when creating a service or task. To do that, just issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ecs register-task-definition --cli-input-json file://devto-task-definition.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make sure the task definition has been successfully created, you can issue the command to confirm:&lt;/p&gt;

&lt;p&gt;aws ecs list-task-definitions&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8b4d0q08pfpwy12zz4kc.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8b4d0q08pfpwy12zz4kc.PNG" alt="Image description" width="800" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the task definition registered, we are finally able to run our task in our ECS cluster (Uhuuuuulll !!!). To do that, lets create a service to run our task and test it from a browser on the internet. To do that, take note about the subnet-id you will deploy the service, the security group for that service (as this is an example, lets use a security group allowing access from internet on port 80) and lets assign a public IP to that, so we will be able to test it from anywhere. With all required information, lets simply issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ecs create-service --cluster devto-ecs-cluster \
--service-name devto-article-service \
--task-definition devto-task-definition \
--desired-count 1 \
--launch-type "FARGATE" \
--network-configuration "awsvpcConfiguration={subnets=[subnet-014d9c5f9d0bb9b90],securityGroups=[sg-03eb793e06078aabe],assignPublicIp=ENABLED}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make sure the service has been created, lets list the services running in our ECS cluster with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ecs list-services --cluster devto-ecs-cluster
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, our service is right there:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xddbimttu7wjsaj3np6.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xddbimttu7wjsaj3np6.PNG" alt="Image description" width="800" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now our container app is running in a service on top of the ECS cluster, that is great !!! So, time to test it. As we deployed in a public subnet to make it available to test in the internet, we need to find the public IP address that was assigned to out task in the service. To grab this information, lets run some commands ! &lt;/p&gt;

&lt;p&gt;First, lets list our task to get the arn. Issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ecs list-tasks --cluster devto-ecs-cluster --service devto-article-service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will output the task arn:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F07m6d4iyfzy6rg5xi7il.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F07m6d4iyfzy6rg5xi7il.PNG" alt="Image description" width="800" height="90"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, lets describe this task using the arn, so we will be able to check which network interface it is using and with that information, check the public IP assigned to the task. Just issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ecs describe-tasks \
--cluster devto-ecs-cluster \
--tasks arn:aws:ecs:us-east-1:&amp;lt;your_account_id&amp;gt;:task/devto-ecs-cluster/defc81a93bda4df6ad73957ef718876e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"Pay attention that I replaced my account id by the string . In your case, it should be your own account id."&lt;/p&gt;

&lt;p&gt;Look for the "networkInterfaceId" value as shown bellow:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn13i4zbtt0bzdcz0k2nd.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn13i4zbtt0bzdcz0k2nd.PNG" alt="Image description" width="800" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the network interface id, we can easily discover the IP address with a describe command. Just issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ec2 describe-network-interfaces \
--network-interface-id eni-0765281dfd52d2b06
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will be as shown bellow:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj4e5b2mf6y2j1hy6o8qo.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj4e5b2mf6y2j1hy6o8qo.PNG" alt="Image description" width="800" height="107"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What amaaaaazing news !!! Now we can test our application from a browser and make sure it is running as expected. So what are we waiting for ? Lets try it right now !!! Lets put the public IP in a browser and have our fingers crossed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9rwodmqkgdbvlw8mcy4b.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9rwodmqkgdbvlw8mcy4b.PNG" alt="Image description" width="591" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Uaaaaauuuu !!! After some commands, we are finally done with our mission to have a container application running on a ECS cluster as required. &lt;/p&gt;

&lt;p&gt;You did a great job. Thank you so much for follow me in this article and see you in the next.&lt;/p&gt;

&lt;p&gt;sources:&lt;br&gt;
&lt;a href="https://aws.amazon.com/getting-started/hands-on/deploy-docker-containers/"&gt;https://aws.amazon.com/getting-started/hands-on/deploy-docker-containers/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-container-image.html"&gt;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-container-image.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html"&gt;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_AWSCLI_Fargate.html#ECS_AWSCLI_Fargate_register_task_definition"&gt;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_AWSCLI_Fargate.html#ECS_AWSCLI_Fargate_register_task_definition&lt;/a&gt; &lt;/p&gt;

</description>
      <category>aws</category>
      <category>awsecs</category>
      <category>ecs</category>
    </item>
    <item>
      <title>AWS ECR - Let's play with it</title>
      <dc:creator>leotoras</dc:creator>
      <pubDate>Wed, 14 Jun 2023 17:56:32 +0000</pubDate>
      <link>https://forem.com/leotoras/aws-ecr-lets-play-with-it-1jb1</link>
      <guid>https://forem.com/leotoras/aws-ecr-lets-play-with-it-1jb1</guid>
      <description>&lt;p&gt;Lets start talking about AWS ECR service, what it is, what it does and so on.&lt;/p&gt;

&lt;p&gt;ECR is a fully managed AWS container image registry service where you can create your public or private repositories, and have it secure, scalable and reliable, where you can push, pull and manage your container images.&lt;/p&gt;

&lt;p&gt;Instead of going so deeper in theory, lets have out hands dirty and perform some tasks to have a real idea about what we are talking about.&lt;/p&gt;

&lt;p&gt;For that, it's nice to have a container image to use as an example, so lets create one !&lt;/p&gt;

&lt;p&gt;I'm going to use an EC2 instance with Amazon Linux 2023 operating systems as my working place, you can choose anyone that fits your needs.&lt;/p&gt;

&lt;p&gt;Lets start updating our instance packages before installing Docker binaries, with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum update -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, lets install Docker with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum install docker -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbfby6vd61f0u2rrjy0p.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbfby6vd61f0u2rrjy0p.PNG" alt="Image description" width="800" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we need to start the Docker service, so you can issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service docker start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoycwq208pzumjaojdnm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoycwq208pzumjaojdnm.PNG" alt="Image description" width="800" height="73"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And to confirm Docker service is up and running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service docker status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwvx8un2ioje2m5k4vj7.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwvx8un2ioje2m5k4vj7.PNG" alt="Image description" width="800" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To remove the need to add "sudo" in front of any docker command, lets make our user part of the Docker group, simply issuing the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo usermod -a -G docker ec2-user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check if everything is working, just check the docker info to retrieve some information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker info
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6f1kn7j2xas50a28cx25.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6f1kn7j2xas50a28cx25.PNG" alt="Image description" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you receive a "permission denied" error trying the command above, don't panic, the only think you need is logout and login again.&lt;/p&gt;

&lt;p&gt;Now we are ready to start working with Docker images and ECR and ECS service !!!&lt;/p&gt;

&lt;p&gt;First thing we need is a file called Dockerfile, where we will describe the base image for our container all the things we need to install to run our app.&lt;br&gt;
You can use any file editor, create the Docker file with the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM ubuntu:22.04

# Update container image and install dependencies
RUN apt-get update &amp;amp;&amp;amp; \
 apt-get -y install apache2

# Install apache and write a message in the index.html file
RUN echo 'Welcome to my DEV.TO article about container on AWS ECS !!!' &amp;gt; /var/www/html/index.html

# Configure apache
RUN echo '. /etc/apache2/envvars' &amp;gt; /root/run_apache.sh &amp;amp;&amp;amp; \
 echo 'mkdir -p /var/run/apache2' &amp;gt;&amp;gt; /root/run_apache.sh &amp;amp;&amp;amp; \
 echo 'mkdir -p /var/lock/apache2' &amp;gt;&amp;gt; /root/run_apache.sh &amp;amp;&amp;amp; \ 
 echo '/usr/sbin/apache2 -D FOREGROUND' &amp;gt;&amp;gt; /root/run_apache.sh &amp;amp;&amp;amp; \ 
 chmod 755 /root/run_apache.sh

EXPOSE 80

CMD /root/run_apache.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it is time to use this Dockerfile and build our image giving it a tag (basically a name for our image). Lets tag it my-ecs-container, so issue the following command (make sure that you are in the directory where the Dockerfile resides):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t my-ecs-container .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As soon as the command completes successfuly, you will see a message like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5zev71rwj12eda5s7rwp.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5zev71rwj12eda5s7rwp.PNG" alt="Image description" width="800" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make sure the image is ready, we can check with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker image ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should be able to see ou image my-ecs-container as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1v734txhs3b4lm9sol9e.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1v734txhs3b4lm9sol9e.PNG" alt="Image description" width="800" height="76"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets recapture what we have done so far:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;installed Docker service in our environment&lt;/li&gt;
&lt;li&gt;created a Dockerfile&lt;/li&gt;
&lt;li&gt;built the docker image and tagged it&lt;/li&gt;
&lt;li&gt;have the image ready locally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is a good point to test our image, right ?&lt;br&gt;
So, lets run this image and see if that works as expected. Just issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker container run -dt -p 80:80 my-ecs-container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output should be the container id that is currently running:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faanedcuetyyehi0hbw0g.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faanedcuetyyehi0hbw0g.PNG" alt="Image description" width="800" height="58"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make sure everything is working properly, lets open a browser, paste the public IP from our environment and see if the Welcome message is displayed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fobt9jac4yzgfephlxwgl.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fobt9jac4yzgfephlxwgl.PNG" alt="Image description" width="704" height="98"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great ! Our container image was successfully built and our container is running as expected !&lt;/p&gt;

&lt;p&gt;Now it is time to visit the AWS ECR service :-)&lt;/p&gt;

&lt;p&gt;We currently have our image locally with us, so we need to push it to a repository where it can be safely pushed and pulled whenever we need it.&lt;br&gt;
Here, ECR comes into picture. We are ready to push our built image to an ECR repo.&lt;/p&gt;

&lt;p&gt;To have this task done, we first need to create an ECR repo, so lets do that. For that, you can use the AWS console to do that visually or you can create using CLI with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws ecr create-repository --repository-name my-ecs-container-repo --region us-east-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will receive an output like that:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fma6iklmslyyj88wsgnrc.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fma6iklmslyyj88wsgnrc.PNG" alt="Image description" width="800" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our ECR repository available, we need to push our container image to that repo. To do that, the image needs to follow a standard name, basically specifying account id, region and repository name, like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;aws_account_id&amp;gt;.dkr.ecr.region.amazonaws.com/&amp;lt;repository-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, before pushing the image to the ECR, lets give that a proper name tagging it using the docker tag command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker tag my-ecs-container &amp;lt;aws_account_id&amp;gt;.dkr.ecr.us-east-1.amazonaws.com/my-ecs-container-repo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3hvtdpvhuwk0iabtpitp.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3hvtdpvhuwk0iabtpitp.PNG" alt="Image description" width="800" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To verify the new image is tagged with the standard name, just issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker image ls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx697abihyh5sgsmmpte9.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx697abihyh5sgsmmpte9.PNG" alt="Image description" width="800" height="87"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next step ! We need to login to our ECR repository to push the image. To do that, we issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker login -u AWS -p $(aws ecr get-login-password --region REGION) aws_account_id.dkr.ecr.REGION.amazonaws.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure to replace the values REGION and aws_account_id for the proper values. You should have the following output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp8dm1hjg6fr1lsm02glz.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp8dm1hjg6fr1lsm02glz.PNG" alt="Image description" width="800" height="105"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally we are able to push our image to the ECR repo and make it secure and ready to be used for example by AWS ECS service (we wil talk about that service in another article). Lets do that, just issue the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker push aws_account_id.dkr.ecr.region.amazonaws.com/my-ecs-container-repo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure to replace with the proper values for the image name. You should have the following output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiobu1zgit2l4m5ph9lu9.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiobu1zgit2l4m5ph9lu9.PNG" alt="Image description" width="800" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to validate our job, you can run your container pulling the image from the ECR repo. Lets give a try, open a browser, paste the public IP from our environment and see if the Welcome message is displayed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa0qo6efb09szy6r8xn71.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa0qo6efb09szy6r8xn71.PNG" alt="Image description" width="800" height="57"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we are finally done with our mission to have a container image pushed to and pulled from an ECR repository !!!&lt;/p&gt;

&lt;p&gt;In the next article, let's play with AWS ECS service.&lt;/p&gt;

&lt;p&gt;You did a great job. Thank you so much for follow me in this article and see you in the next. &lt;/p&gt;

&lt;p&gt;sources:&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-container-image.html"&gt;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-container-image.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html"&gt;https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html&lt;/a&gt; &lt;/p&gt;

</description>
      <category>aws</category>
      <category>ecr</category>
      <category>awsecr</category>
    </item>
  </channel>
</rss>
