So far, we have successfully Dockerized the Snake and Ladder game and verified that it runs perfectly on our local machine. That’s a great first milestone.
But running a Docker image only on one machine isn’t enough.
In real-world applications, we need a place where our Docker images can be stored, shared, and reused—so they can be pulled by servers, cloud services, or container platforms like ECS and Kubernetes.
In this next step, we will push our Docker image to a container registry, making it accessible beyond our local system. We’ll also understand the two most commonly used Docker repositories:
Docker Hub – for public and learning use cases
Amazon ECR (Elastic Container Registry) – for secure, production-ready AWS deployments
What Is Docker Hub?
Docker Hub is a cloud-based repository where you can store, share, and download Docker images.
Think of Docker Hub as GitHub for Docker images.
What Docker Hub Does?
Stores Docker images online
Lets you push your images
Lets others pull and use them
-
Hosts thousands of pre-built images like:
- nginx, mysql, node, python
🔹 Key Features
Public and private repositories
Easy to use for beginners
Free public image hosting
Widely used for learning and open-source projects
Creating a Repository in Docker Hub
First, We need to create a Repository to DockerHub. If you already have an account in Dockerhub. You can simply Sign In else do a Sign Up
I am Signing In, and Next step is to create a repository
Click Create Repository button, Provide a name and a short description and

Click Create button. Remember, we have chosen a public repository
We have successfully created a repository in Docker Hub
Push the Snake and Ladder Docker Image to Repository in Docker Hub
Lets come back to ec2 console,

Come back to your EC2 instance and connect to it using EC2 Instance Connect.
Type docker images command to see the available images.
Now Authenticate Docker with Docker Hub using the EC2 command line.
Run the following command:
docker login
When prompted, enter your Docker Hub username and password.
After a successful login, you will see a confirmation message indicating that Docker is now authenticated with Docker Hub.
Now, let’s tag the Snake and Ladder Docker image so it can be pushed to Docker Hub.
Docker Hub requires images to follow a specific naming format:
docker-username/repository-name:tag
In our case, we will tag the image as:
nandinivijayr/snake-ladder-game:latest
Run the following command:
docker image tag snake-ladder-game:latest nandinivijayr/snake-ladder-game:latest
By tagging the image in this format, Docker knows which Docker Hub repository the image belongs to, making it ready to be pushed to Docker Hub in the next step.
Now lets verify if the image is tagged properly by using Docker images command
Now lets push the image to Docker hub using the below command
docker push nandinivijayr/snake-ladder-game
Push the Docker Image to Amazon ECR
Amazon ECR (Elastic Container Registry) is a fully managed container image registry service provided by AWS. It is used to store, manage, and secure Docker container images so they can be easily deployed on AWS services like ECS, EKS, and Fargate.
In simple terms:
👉 ECR is AWS’s private Docker image repository.
Why Do We Need ECR?
When applications are containerized using Docker, the images need a secure place to live so cloud services can pull and run them. Amazon ECR provides that storage inside AWS, with built-in security and scalability.
Key Features of Amazon ECR
Secure by Default
Repositories are private by default
Access is controlled using IAM roles and policies
No usernames or passwords required
Deep AWS Integration
Works seamlessly with: Amazon ECS, Amazon EKS, AWS Fargate
Images can be pulled directly by AWS services
Fully Managed
No servers to manage
Automatically scales
Highly available and reliable
Image Management
Version images using tags
Scan images for vulnerabilities
Store multiple versions safely
Now, Lets see how we can push image to ECR
Create an ECR Repository
Go to home page of aws console and Navigate to the ECR service
Create a private ECR repository using AWS Console by clicking Create Repository button
Provide a repository name and scroll down
Go with the default values and click create button
Wait for a couple of minutes, You can see the new repository entry under Private Repositories
Come back to your EC2 instance and connect to it using EC2 Instance Connect.
Now Lets Authenticate Docker to ECR using the below command
aws ecr get-login-password --region <region> | \
docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com
Authenticate Docker with Amazon ECR from EC2
Before pushing a Docker image to Amazon ECR, Docker must be authenticated with AWS.
The recommended and secure way is to use an IAM role attached to the EC2 instance.
- Create an IAM Role for EC2
Go to IAM → Roles → Create role
Choose AWS service → EC2
Attach the policy:
AmazonEC2ContainerRegistryFullAccess
Create the role by providing a role name and clicking Create Role button
- Attach the Role to EC2
Go to EC2 → Instances
Select your instance
Actions → Security → Modify IAM role
Here Select the I A M role that was created in the previous step and click Update IAM Role button
Wait 1–2 minutes for changes to apply.
- Verify the Role
On the EC2 instance, run:
aws sts get-caller-identity
Sample output:
{
"Account": "123456789",
"Arn": "arn:aws:sts::123456789:assumed-role//i-0fea76487ea9663b1"
}
- Login to Amazon ECR
Docker uses a temporary token generated by AWS.
aws ecr get-login-password --region ap-south-1 | \
docker login --username AWS --password-stdin \
123456789.dkr.ecr.ap-south-1.amazonaws.com
Expected Output
Login Succeeded
Note: Replace 123456789 with your own AWS Account ID.
Do not change the username or password values — the username must be AWS, and the password is automatically passed using --password-stdin.
Now push the image to ecr respository that was created
Push Docker Image to Amazon ECR Repository
Now that Docker authentication is successful, the next step is to push the Docker image to the Amazon ECR repository created earlier. This makes the container image available for deployment using AWS services such as Amazon ECS, App Runner, or EKS.
Let’s tag the Snake and Ladder Docker image with the ECR repository URI so it’s ready to be pushed.
Use the following command to tag
docker tag <IMAGE NAME> <ECR Repository URI>
IMAGE NAME is snake-ladder-game which we built earlier. You can get it using docker images command
Now let us push the tagged image using docker push command
docker push <ECR Repository URI>
Docker will upload the image layers to Amazon Elastic Container Registry (ECR). Depending on the image size, this process may take a few moments.
Verify the Image in Amazon ECR
After the push completes:
Open the AWS Management Console
Navigate to Amazon ECR → Repositories
Select your repository
Confirm that the image with the latest tag is listed



















Top comments (0)