Saturday, November 7, 2020

Docker basics for Amazon ECS

Create a Docker Image

https://timhieuvedocker.blogspot.com/2020/11/dockerizing-nodejs-web-app.html 

Push your image to Amazon Elastic Container Registry

Amazon ECR is a managed AWS Docker registry service. Customers can use the familiar Docker CLI to push, pull, and manage images. For Amazon ECR product details, featured customer case studies, and FAQs, see the Amazon Elastic Container Registry product detail pages.

This section requires the following:

To tag your image and push it to Amazon ECR

  1. Create an Amazon ECR repository to store your nodejs-docker-webapp image. Note the repositoryUri in the output.

    aws ecr create-repository --repository-name nodejs-docker-webapp --region region

    Output:

    {
        "repository": {
            "registryId": "aws_account_id",
            "repositoryName": "nodejs-docker-webapp",
            "repositoryArn": "arn:aws:ecr:region:aws_account_id:repository/nodejs-docker-webapp",
            "createdAt": 1505337806.0,
            "repositoryUri": "aws_account_id.dkr.ecr.region.amazonaws.com/nodejs-docker-webapp"
        }
    }
  2. Tag the nodejs-docker-webapp image with the repositoryUri value from the previous step.

    docker tag nodejs-docker-webapp aws_account_id.dkr.ecr.region.amazonaws.com/nodejs-docker-webapp
  3. Run the aws ecr get-login-password command (only apply for AWS CLI version 2). Specify the registry URI you want to authenticate to. For more information, see Registry Authentication in the Amazon Elastic Container Registry User Guide.

    aws ecr get-login-password | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com
  4. Push the image to Amazon ECR with the repositoryUri value from the earlier step.

    docker push aws_account_id.dkr.ecr.region.amazonaws.com/nodejs-docker-webapp

Clean up

When you are done experimenting with your Amazon ECR image, you can delete the repository so you are not charged for image storage.

aws ecr delete-repository --repository-name nodejs-docker-webapp --region region --force

No comments:

Post a Comment