DevOps · Docker Basics
Docker Basics Explained in Plain Simple Language
Quick summary — Docker basics in plain simple language
Docker lets you package your app and everything it needs into a single box that runs the same way on any machine. No more "it works on my laptop" problems. This guide explains the basics in plain simple language — no prior DevOps knowledge required.
In this guide you will learn:
- What is Docker and why it matters — in plain simple language.
- Containers vs virtual machines — the key difference.
- Images vs containers — the recipe vs the cooked dish.
- Your first Dockerfile — step-by-step with examples.
- Volumes, networking & Docker Compose — practical examples.
SECTION 01What is Docker and Why It Matters
Docker is a tool that packages your application and everything it needs — code, libraries, dependencies, and settings — into a single unit called a container. Here's the plain simple version:
| Term | Plain Simple Meaning | Everyday Analogy | Why It Matters |
|---|---|---|---|
| Docker | A tool for running apps inside containers | A lunchbox factory | Same app runs on every machine |
| Container | A running box with your app inside | A sealed lunchbox with your meal | Isolated, portable, fast |
| Image | A saved recipe of your container | The recipe card | You can build many containers from it |
| Dockerfile | A text file listing steps to build an image | The steps on the recipe card | Repeatable and version-controlled |
| Docker Hub | An online store for images | A supermarket of recipes | Reuse images made by others |
Docker — Core Concepts in Plain Words:
Docker:
A tool that lets you package an app with
everything it needs so it runs the same way
everywhere.
Container:
A live, running version of your app.
It has its own filesystem, network, and processes,
but shares the host OS kernel.
Image:
A read-only template used to create containers.
Think of it as a snapshot of your app + environment.
Dockerfile:
A text file with step-by-step instructions
to build an image.
Registry (e.g., Docker Hub):
A place to store and share images.
Why Docker matters:
- Ends "works on my machine" problems
- Faster onboarding and deployment
- Lightweight compared to virtual machines
- Easy to ship, scale, and roll back
Docker — Explained Like You're 10:
Imagine you bake a cake.
You want the same cake in every kitchen in the world.
So you write down:
1. Ingredients
2. Oven temperature
3. Baking time
That list is the Dockerfile.
The finished cake is the image.
A slice served on a plate is a container.
Now anyone with the recipe can make the exact
same cake — no matter where they live.
That's Docker in one sentence:
A recipe that guarantees the same cake
in every kitchen.
Why it matters:
- Your app runs the same on your laptop
and in production.
- New team members get set up in minutes.
- Deployment becomes repeatable and safe.
SECTION 02Containers vs Virtual Machines
Both isolate apps, but they work very differently. Here's the plain simple comparison:
| Aspect | Virtual Machine | Container | Plain Meaning |
|---|---|---|---|
| OS | Full OS per VM | Shares host OS kernel | Containers are lighter |
| Size | Gigabytes | Megabytes | Faster to ship |
| Boot time | Minutes | Seconds | Faster iteration |
| Isolation | Stronger (separate OS) | Process-level isolation | Good enough for most apps |
| Density | Few per host | Many per host | Better resource usage |
| Use case | Full OS environments | Apps and microservices | Containers for apps |
Containers vs Virtual Machines — Plain Simple:
Virtual Machine:
- Includes a full guest operating system
- Boots slowly (minutes)
- Heavier (GBs)
- Stronger isolation
- Good for running different OS types
Container:
- Shares the host OS kernel
- Boots in seconds
- Lightweight (MBs)
- Process-level isolation
- Great for apps and microservices
One-line summary:
VMs virtualize hardware.
Containers virtualize the operating system.
Real-world impact:
10 containers can easily run on a laptop.
10 VMs would likely crash it.
When to Use Which:
Use a VM when:
□ You need a different OS than the host
□ You need strong security isolation
□ You are running legacy software
□ You want full system-level control
Use a container when:
□ You are deploying an app or microservice
□ You need fast build/run cycles
□ You want consistent dev and production
□ You are using CI/CD pipelines
□ You want to pack many services on one host
Reality check:
Most modern apps use containers
for deployment and VMs for infrastructure.
SECTION 03Images vs Containers
This is the most confused pair in Docker. Here's the plain simple version:
| Aspect | Image | Container | Analogy |
|---|---|---|---|
| What it is | A read-only template | A running instance of an image | Recipe vs cooked dish |
| Mutable? | No — it's a snapshot | Yes — it can change while running | Photo vs live person |
| State | Static file | Running process | Blueprint vs building |
| Count | One image, many containers | Many containers per image | One recipe, many servings |
| Command | docker build |
docker run |
Build vs run |
Images vs Containers — Plain Simple:
Image:
- A packaged snapshot of your app
- Contains code, runtime, libraries, settings
- Built once, reused many times
- Does not run by itself
Container:
- A running instance of an image
- Has its own process and (optional) writable layer
- You can start, stop, and delete containers
- Many containers can run from one image
Analogy:
Image = recipe card
Container = cooked dish
Everyday example:
The official nginx image is downloaded once.
You can run 3 nginx containers from it,
each with its own port and config.
Key commands:
docker build -t myapp:1.0 . # create image
docker run -d -p 8080:80 myapp:1.0 # run container
Common Docker Commands:
Images:
docker images # list images
docker build -t myapp . # build an image
docker pull nginx # download an image
docker rmi # remove an image
Containers:
docker ps # list running containers
docker ps -a # list all containers
docker run -it ubuntu bash # run a container interactively
docker run -d -p 8080:80 nginx # run in background
docker stop # stop a container
docker rm # remove a container
Logs and shells:
docker logs # view logs
docker exec -it bash # open a shell
Rule of thumb:
Image = "build" and "pull"
Container = "run" and "stop"
SECTION 04Your First Dockerfile
A Dockerfile is a text file with simple instructions. Here's a beginner-friendly example for a small Node.js app:
# Dockerfile — a simple Node.js app
# 1. Start from a base image
FROM node:20-alpine
# 2. Set the working directory inside the container
WORKDIR /app
# 3. Copy package files first (better caching)
COPY package*.json ./
# 4. Install dependencies
RUN npm install
# 5. Copy the rest of the source code
COPY . .
# 6. Tell Docker which port the app uses
EXPOSE 3000
# 7. Command to start the app
CMD ["npm", "start"]
# Build the image
docker build -t my-node-app:1.0 .
# Run a container from the image
docker run -d -p 3000:3000 --name my-node my-node-app:1.0
# View logs
docker logs -f my-node
# Stop and remove the container
docker stop my-node
docker rm my-node
# Remove the image (optional)
docker rmi my-node-app:1.0
# What just happened?
# 1. FROM → started from an official Node.js image
# 2. WORKDIR→ set the folder inside the container
# 3. COPY → brought our source code in
# 4. RUN → installed dependencies during build
# 5. EXPOSE → documented the port
# 6. CMD → told the container how to start
SECTION 05Volumes, Networking & Docker Compose
Containers are temporary by default. Here's how to keep data, connect containers, and run multi-container apps:
| Concept | Plain Meaning | Analogy | Command |
|---|---|---|---|
| Volume | Persistent storage outside the container | A USB drive for your lunchbox | docker run -v mydata:/app/data ... |
| Port mapping | Expose a container port to your host | A window on the box | -p 8080:80 |
| Network | A private network for containers to talk | A room with many people | docker network create mynet |
| Compose | A YAML file to run multiple containers | A team of chefs | docker compose up |
# Volumes — keep data even if the container is deleted
# Named volume
docker volume create mydata
docker run -d -v mydata:/var/lib/mysql mysql:8
# Bind mount (host folder inside the container)
docker run -d -v $(pwd)/site:/usr/share/nginx/html nginx
# Networking — let containers talk to each other
docker network create mynet
docker run -d --name db --network mynet mysql:8
docker run -d --name app --network mynet -p 3000:3000 my-node-app:1.0
# Inside the "app" container, "db" is reachable
# by hostname: db:3306
Plain simple:
Volumes keep data safe.
Networks let containers talk by name.
Ports let you reach a container from your laptop.
# docker-compose.yml — run multiple containers together
services:
app:
build: .
ports:
- "3000:3000"
depends_on:
- db
environment:
DB_HOST: db
DB_USER: user
DB_PASS: secret
db:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- dbdata:/var/lib/mysql
volumes:
dbdata:
# Run everything
# docker compose up -d
#
# See logs
# docker compose logs -f
#
# Stop everything
# docker compose down
#
# Rebuild after code changes
# docker compose up -d --build
SECTION 06Interview Q&A — Docker basics
Q1What is Docker in simple words?
Docker is a tool that packages an app with everything it needs into a container, so it runs the same way on any machine. It ends the "works on my machine" problem.
Q2What's the difference between an image and a container?
An image is a read-only template (a recipe). A container is a running instance of that image (the cooked dish). You can create many containers from one image.
Q3Containers vs virtual machines — which is better?
They serve different purposes. Containers are lighter, faster, and share the host kernel. VMs give stronger isolation with a full OS. Use containers for apps, VMs for infrastructure.
Q4What is a Dockerfile?
A Dockerfile is a text file with step-by-step instructions for building a Docker image. It defines the base image, dependencies, files to copy, ports, and the start command.
Q5What is Docker Compose used for?
Docker Compose lets you define and run multi-container apps with a single YAML file. You describe your app, database, and other services, and start them all with one command.
SECTION 07Test yourself — Docker basics quiz
Five questions. No sign-up.
0 / 5Pick an answer to see why it is right or wrong.
SECTION 08Frequently asked questions
Is Docker the same as a virtual machine?
No. VMs include a full guest OS and are heavier. Containers share the host OS kernel and are much lighter and faster to start.
Do I need to know Linux to use Docker?
Basic Linux knowledge helps, but you don't need to be an expert. Understanding the terminal and file paths is enough to start.
What is Docker Hub?
Docker Hub is the default online registry for Docker images. You can download popular images like nginx, node, or postgres, and publish your own.
What's the difference between EXPOSE and -p?
EXPOSE in a Dockerfile is just documentation — it does not publish the port. The -p flag on docker run actually maps a container port to your host.
How do I persist data in a container?
Use a volume. Named volumes (like mydata:/app/data) survive container restarts and deletion. Bind mounts map a host folder directly into the container.
SECTION 09Related reads
Classroom & online
Your Docker journey starts now
Our Docker & Kubernetes Training Course is designed for beginners — with hands-on labs, real projects, and interview prep that get you job-ready.
₹15,500 · full programme- Complete Docker roadmap
- Hands-on lab projects
- Mock interviews
- Weekday & weekend batches