πŸš€ 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

  1. Go to hub.docker.com

  2. 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

0
Subscribe to my newsletter

Read articles from Tathagat Gaikwad directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tathagat Gaikwad
Tathagat Gaikwad