Skip to main content

Command Palette

Search for a command to run...

Module 1: Introduction to Docker

Updated
•4 min read•View as Markdown

🔹 What is Docker & Why Do We Need It?

Imagine you built an app that runs perfectly on your laptop. But when you send it to your friend or deploy it on a server, it breaks because of different environments, dependencies, or OS versions. This is the classic “it works on my machine” problem.

👉 Docker solves this by packaging your application and all its dependencies into containers.

  • A container is a lightweight, isolated environment that runs your app the same way everywhere.

  • No more dependency conflicts, OS mismatches, or version hell.

In short: Docker ensures consistency, portability, and scalability.


🔹 Virtual Machines vs Containers

Many beginners confuse VMs (Virtual Machines) with Containers. Let’s clear that up.

FeatureVirtual MachinesContainers
OSEach VM has its own full OS (heavy)Containers share the host OS kernel (lightweight)
SizeGBsMBs
Startup TimeMinutesSeconds
PerformanceMore overheadNear-native speed
Use CaseFull OS isolationApplication-level isolation

👉 Think of VMs as entire houses (independent, heavy) and containers as apartments (lightweight, share infrastructure).


🔹 Key Docker Components

Before diving deeper, let’s understand the building blocks of Docker:

  1. Docker Images

    • Read-only templates that define how a container should run.

    • Example: nginx:latest, mysql:8.0.

  2. Docker Containers

    • Running instances of images.

    • Example: Running mysql:8.0 with your DB.

  3. Docker Volumes

    • Used to store persistent data outside the container’s lifecycle.

    • Example: Keeping your database files safe even if the container restarts.

  4. Docker Networks

    • Allow communication between containers.

    • Example: Your Node.js app container talking to a MySQL container.


🔹 Docker Architecture

Now that we know the components, let’s see how they all fit together in Docker’s architecture.

Docker follows a client-server model with three main parts:

  1. Docker Client – where users interact using CLI (docker run), REST API, or GUI.

  2. Docker Host – contains the Docker Daemon, which manages containers, images, volumes, and networks.

  3. Docker Registry – stores Docker images (e.g., Docker Hub).

🔗 Workflow Example

  1. You run:

     docker run nginx
    
  2. The Docker Client sends this request to the Docker Daemon.

  3. The Daemon checks if the nginx image exists locally.

    • If not → it pulls from the Registry.
  4. The Daemon then creates a container from that image.

  5. The container runs in isolation but can communicate using networks and persist data with volumes.

👉 This architecture ensures Docker runs applications in a consistent, portable, and efficient way.

🔹 Installing Docker

Docker supports all major platforms. Here’s a quick guide:

✅ On Linux (Ubuntu/Debian)

sudo apt update
sudo apt install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io

Verify installation:

docker --version

✅ On Windows / Mac

docker --version

🔹 Your First Container

Now that Docker is installed, let’s run our very first container! 🎉

docker run hello-world

🔍 What happens here?

  1. Docker checks if the hello-world image exists locally.

  2. If not, it downloads it from Docker Hub (public registry).

  3. Runs the container, which prints a welcome message.

You should see output like:

Hello from Docker!
This message shows that your installation appears to be working correctly.

🎊 Congratulations — you just ran your first container!


📌 Recap

In this module, you learned:
✅ What Docker is and why we need it
✅ Difference between VMs and Containers
✅ Key Docker components (Images, Containers, Volumes, Networks)
✅ How to install Docker on Linux/Mac/Windows
✅ Running your very first container with hello-world


Mastering Docker: The Complete Guide

Part 1 of 14

This series takes you on a journey from Docker basics to advanced real-world applications. You’ll learn everything from running your first container, building images, and managing networks, to multi-container setups, CI/CD pipelines.

Up next

Module 2: Docker Basics

🔹 1. Common Docker CLI Commands Here are some of the most commonly used Docker commands that you’ll use daily: CommandDescriptionExample docker psLists running containersdocker ps docker ps -aLists all containers (including stopped ones)dock...

More from this blog

D

DevOps Launchpad - Learn DevOps,Cloud, and Kubernetes

26 posts