Build and Publish a Container in AWS to an ECR Repository

Hands-On Lab

 

Photo of Mark Richman

Mark Richman

AWS Training Architect II in Content

Length

00:30:00

Difficulty

Intermediate

In this hands-on AWS Learning Activity, you will create your own ECR repository and then build, tag, and push a Docker container to it.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Build and Publish a Container in AWS to an ECR Repository

Introduction

In this hands-on lab, we will create our own ECR repository and then build, tag, and push a Docker container to it.

Solution

Log in to the live AWS environment using the credentials provided. Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

Also, open a terminal session and log in to the bastion host via SSH using the provided credentials.

Create an Access Key

  1. In the AWS console, navigate to IAM.
  2. Click Users in the left-hand menu.
  3. Click cloud_user.
  4. In the Security Credentials tab, click Create access key.
  5. Either download the .csv file, or copy the access key ID and secret access key and paste them into a text file.

Create an ECR Repository

  1. In the terminal, configure the AWS CLI:

    aws configure
  2. Then, set the following values:

    AWS Access Key ID [None]: <ACCESS KEY ID>
    AWS Secret Access Key [None]: <SECRET ACCESS KEY>
    Default region name [None]: us-east-1
    Default output format [None]:
  3. Get an authorization token from ECR:

    (aws ecr get-login --no-include-email)

Tag and Push a Docker Image to ECR

  1. In the terminal, clone the course repository:

    git clone https://github.com/linuxacademy/ecs-deep-dive-2018.git
  2. Change to the course GitHub directory:

    cd ecs-deep-dive-2018/
  3. Look in the picture-upload directory:

    cd picture-upload/
    
    ls
  4. Change to the apps directory:

    cd apps
    
    ll
  5. Change to photo-filter:

    cd photo-filter
    
    ll
  6. Check out the Dockerfile:

    cat Dockerfile
  7. Use the Dockerfile to build the container:

    docker build --rm -t photo-filter .
  8. Once it's built, confirm it:

    docker images
  9. In the AWS console, navigate to ECS.

  10. Click Repositories in the left-hand menu, and click Get started.

  11. Give it a name of "photo-filter".

  12. Copy the repository URI, and paste it into a text file.

  13. Click Next step.

  14. Copy the docker tag command on the page, and enter it in the terminal to tag the image.

  15. Copy the docker push command listed on the page in the AWS console, and enter it in the terminal to push the image.

  16. Verify its success by entering:

    aws ecr describe-images --repository-name photo-filter

Conclusion

Congratulations on completing this hands-on lab!