π Day 17 of DevOps Interview Preparation β Push Image to DockerHub

Series: 30 Days DevOps Interview Preparation
Author: Tathagat Gaikwad
Welcome to Day 17 of the 30 Days DevOps Interview Preparation Challenge!
Today we dive into a core DevOps workflow β pushing Docker images to DockerHub, which is the bridge between local development and collaborative deployments in CI/CD pipelines.
πΉ What is DockerHub?
DockerHub is a cloud-based container image registry where developers and DevOps engineers can:
Store, manage, and distribute Docker images.
Use public repositories for open-source projects.
Use private repositories for enterprise use cases.
Automate builds and scanning for vulnerabilities.
In short: Build locally β Push to DockerHub β Pull anywhere.
π οΈ Practical: Push Docker Image to DockerHub (on AWS EC2)
Letβs walk through the step-by-step guide.
Step 1: Setup Environment
Launch an AWS EC2 instance (Amazon Linux 2 or Ubuntu).
# Update system
sudo apt-get update -y
# Install Docker
sudo apt-get install docker.io -y
# Start Docker service
sudo systemctl start docker
sudo systemctl enable docker
# Add user to docker group (avoid sudo)
sudo usermod -aG docker $USER
Re-login to apply changes.
Step 2: Create DockerHub Account
Go to hub.docker.com
Sign up and create a repository (e.g.,
tathagatgaikwad22/myapp
).
Step 3: Build a Docker Image
Create a simple Node.js app:
app.js
const express = require("express");
const app = express();
app.get("/", (req, res) => res.send("Hello from DockerHub!"));
app.listen(3000, () => console.log("App running on port 3000"));
Dockerfile
FROM node:16
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "app.js"]
Build the image:
docker build -t myapp:latest .
Step 4: Tag the Image
DockerHub requires tagging with your username/repo:tag format:
docker tag myapp:latest tathagatgaikwad22/myapp:v1
Step 5: Login and Push to DockerHub
docker login
# enter DockerHub username & password
docker push tathagatgaikwad22/myapp:v1
Step 6: Verify the Image
Go to DockerHub β Repositories, and youβll see myapp:v1
.
Now anyone can pull it with:
docker pull tathagatgaikwad22/myapp:v1
docker run -d -p 3000:3000 tathagatgaikwad22/myapp:v1
π Theory: Why Push to DockerHub?
Centralized Registry β Images are available globally.
Version Control β Tagging allows multiple versions (
dev
,prod
,v1
,v2
).Collaboration β Teams can pull consistent images.
Integration β Works seamlessly with Kubernetes, AWS ECS, Jenkins, GitHub Actions.
Security β Private repos and vulnerability scanning.
π― Interview Questions & Answers
πΉ Q1. Why do we use DockerHub instead of just local images?
π Because local images are limited to a machine. DockerHub makes them globally accessible, versioned, and sharable across teams & CI/CD pipelines.
πΉ Q2. Difference between docker push
and docker save
?
π docker push
uploads an image to a remote registry (e.g., DockerHub).
π docker save
exports an image to a local tar file.
πΉ Q3. How do you secure Docker images in DockerHub?
π Use private repositories, enable image scanning, follow least privilege access policies, and avoid storing secrets in images.
πΉ Q4. Whatβs the difference between DockerHub and AWS ECR?
π DockerHub β Public, general-purpose container registry.
π AWS ECR β AWS-managed private registry, integrated with ECS, EKS, IAM for enterprise use cases.
πΉ Q5. How do CI/CD pipelines use DockerHub?
π After CI builds & tests an app β image is tagged & pushed to DockerHub β CD systems (like Kubernetes or ECS) pull images for deployment.
β Key Takeaways
DockerHub is GitHub for containers.
Always tag images meaningfully (
latest
,v1.0
,dev
).Security is critical: scan and restrict access.
Pushing to DockerHub is a DevOps fundamental that connects dev β CI/CD β production.
π¬ Question for you:
π Do you prefer DockerHub or cloud-native registries (ECR, ACR, GHCR) for production use?
#DevOps #Docker #DockerHub #CICD #InterviewPreparation #AWS
Subscribe to my newsletter
Read articles from Tathagat Gaikwad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
