Cloudaffaire Debjeet: Amazon Ecr Public Gallery
Cloudaffaire Debjeet: Amazon Ecr Public Gallery
Hello Everyone
Today we will discuss how to create a public repository in AWS Elastic Container Registry (ECR) using
AWS CLI. We will also discuss on how to push and pull a docker image from AWS ECR public
repository using AWS CLI.
Amazon Elastic Container Public Registry is a managed AWS container image registry service that is
secure, scalable, and reliable. Amazon ECR supports public image repositories with resource-based
permissions using AWS IAM so that specific users can access your public repositories to push images.
Developers can use their preferred CLI to push and manage Docker images, Open Container Initiative
(OCI) images, and OCI compatible artifacts. Your images are publicly available to pull, either
anonymously or using an Amazon ECR Public authentication token.
The Amazon ECR Public Gallery is the public portal that lists all public repositories hosted on Amazon
ECR Public. Visit the Amazon ECR Public Gallery at https://gallery.ecr.aws.com
Registry:
A public registry is provided to each AWS account; you can create public image repositories in your
public registry and store images in them.
Authorization token:
Your client must authenticate to a public registry as an AWS user before it can push images to a
public repository. For image pulls, Amazon ECR Public accepts both anonymous pulls and pulls using
an authentication token.
Repository:
An Amazon ECR image repository contains your Docker images, Open Container Initiative (OCI)
images, and OCI compatible artifacts.
Repository policy:
You can control access to your repositories and the images within them with repository policies.
Image:
You can push and pull container images to your repositories. You can use these images locally on
your development system, or you can use them in Amazon ECS task definitions and Amazon EKS pod
specifications.
Enough of theory, let us create a new public repository in AWS ECR using CLI.
How to create a public repository in Amazon Elastic Container Registry (ECR) using AWS CLI?
Prerequisites:
Step 1: Get details on your AWS ECR public registry using AWS CLI.
## {
## "registries": [
## {
## "registryId": "<AWS_ACCOUNT_ID>",
## "registryArn":
"arn:aws:ecr-public::<AWS_ACCOUNT_ID>:registry/<AWS_ACCOUNT_ID>",
## "registryUri": "public.ecr.aws/p4j8n4a3",
## "verified": false,
## "aliases": [
## {
## "name": "p4j8n4a3",
## "status": "ACTIVE",
## "primaryRegistryAlias": true,
## "defaultRegistryAlias": true
## }
## ]
## }
## ]
## }
Note: When you create a new AWS account, AWS automatically assigns a public registry in “us-east-
1” region of your ECR service.
## {
## "registryCatalogData": {
## "displayName": "cloudaffaire"
## }
## }
Note: This display name will be visible to the public in AWS public image gallery
Step 3: Create a new public repository in AWS ECR using AWS CLI.
## {
## "repository": {
## "repositoryArn":
"arn:aws:ecr-public::<AWS_ACCOUNT_ID>:repository/my_public_repo",
## "registryId": "<AWS_ACCOUNT_ID>",
## "repositoryName": "my_public_repo",
## "repositoryUri": "public.ecr.aws/p4j8n4a3/my_public_repo",
## "createdAt": "2022-03-07T10:58:31.608000+00:00"
## },
## "catalogData": {
## "description": "This is a test public ECR repository",
## "architectures": [
## "x86"
## ],
## "operatingSystems": [
## "Linux"
## ],
## "logoUrl":
"https://<some_junk>.cloudfront.net/logo/<some_junk>.png",
## "aboutText": "This repository is created for demo purpose",
## "usageText": "This repository is not for public use."
## }
## }
You can also create a new public ECR repository from AWS management console.
Step 4: Get details on AWS ECR public repository using AWS CLI.
## {
## "repositories": [
## {
## "repositoryArn": "arn:aws:ecr-
public::<AWS_ACCOUNT_ID>:repository/my_public_repo",
## "registryId": "<AWS_ACCOUNT_ID>",
## "repositoryName": "my_public_repo",
## "repositoryUri": "public.ecr.aws/p4j8n4a3/my_public_repo",
## "createdAt": "2022-03-07T10:58:31.608000+00:00"
## }
## ]
## }
Next, we will create a docker image in our local system and authenticate, tag and push the docker
image to AWS ECR public repository.
Step 5: Create a new docker image and push the image to AWS ECR public repository.
## Create a Dockerfile
cat << EOF > Dockerfile
FROM ubuntu:18.04
# Install dependencies
RUN apt-get update && \
apt-get -y install apache2
# Configure apache
RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh && \
echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh && \
echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh && \
echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh && \
chmod 755 /root/run_apache.sh
EXPOSE 80
CMD /root/run_apache.sh
EOF
## returns public.ecr.aws/p4j8n4a3/my_public_repo
## {
## "imageDetails": [
## {
## "registryId": "<AWS_ACCOUNT_ID>",
## "repositoryName": "my_public_repo",
## "imageDigest": "sha256:<some_junk>",
## "imageTags": [
## "latest"
## ],
## "imageSizeInBytes": 86243237,
## "imagePushedAt": "2022-03-08T13:51:37+00:00",
## "imageManifestMediaType":
"application/vnd.docker.distribution.manifest.v2+json"
## }
## ]
## }
You can also view your public images in AWS public image gallery.
Hope you have enjoyed this article, to get more details on AWS ECR, please follow below link.
https://docs.aws.amazon.com/ecr/index.html