Learn to Upload a Docker Container Into Amazon Ecr
I. Introduction This blog will detail the process of uploading a docker image into Amazon ECR. Prerequisites: You must have an Am...
https://www.czetsuyatech.com/2020/04/aws-upload-a-docker-container-into-amazon-ecr.html
I. Introduction
This blog will detail the process of uploading a docker image into Amazon ECR.Prerequisites:
- You must have an Amazon Web Service Account
II. Creating an ECR
- Login to your AWS account.
- In the top left corner, click Service and filter the word ECR. You should see the following screen.
- Click the "Create a Repository" button and enter the repository named "hello-world".
- Click "Create Repository". We will use this repository later when we upload the docker image.
- Take note of the region. Eg. us-west-2.
III. Create an IAM Account that we can use to push this image
- Again click the Service menu and filter for "IAM".
- In the IAM, click the Users menu item on the left side and create a user. What's important is the security credentials, the access and secret key that we will use to log in later (take note of these values).
- Make sure to add the following permissions:
- IAMUserChangePassword
- AmazonEC2ContainerRegistryFullAccess
IV. Installing AWS CLI 2.x on Linux
Yes, we will use version 2.x and not 1.x.
- Follow this guide: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html#cliv2-linux-install.
- When installing the aws cli make sure to add the --update flag.
>sudo ./aws/install --update
So in summary here's what we need to execute:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip sudo ./aws/install
Common problem: On some machine, like Amazon Linux 2 AMI (HVM), the default aws cli version is installed (1.x). We need to update it. To do that we need to remove the existing aws and aws_completer in the /usr/local/bin folder and replace it with the newer versions.
cd /usr/local/bin sudo rm aws aws_completer sudo ln -s /usr/local/aws-cli/v2/2.0.7/dist/aws aws sudo ln -s /usr/local/aws-cli/v2/2.0.7/dist/aws_completer aws_completer
V. Configuring AWS Locally
- Run aws_configure and enter the access and secret keys that we have created earlier. Set the region and leave the default output format.
- Now we are ready to push our docker image.
VI. Creating and Build the Dockerfile
For the sake of this demo, we will just extend the hello-world image. You can create a temp directory wherever you want.
- Create a file Dockerfile.
- And input "FROM hello-world".
- Build Docker file by running: docker build .
- Don't forget . at the end of build
V. Pushing the Docker Image to AWS
- Open Service / ECR.
- Click the hello-world ecr.
- Hit View Push command in the top right corner.
- Execute the given commands one at a time.
- Once done, go back to Amazon and refresh the hello-world ecr. You should arrive at the screenshot below.
VI. Common Problems
- aws get-login-password - https://stackoverflow.com/questions/50151833/cannot-login-to-docker-account
Post a Comment