Before Docker, deploying software was painful. "It works on my machine" was a running joke — and a real problem. Containers solve this once and for all.
| Feature | Virtual Machine | Container |
|---|---|---|
| Startup time | 30–120 seconds | < 1 second |
| Size | GBs | MBs |
| OS overhead | Full OS per VM | Shares host OS kernel |
| Isolation | Hardware-level | Process-level |
| Portability | Good (OVF format) | Excellent (Docker Hub) |
A container is a standardised, isolated process that packages:
The same container image runs identically on:
┌─────────────────────────────────────────┐
│ Your Machine │
│ ┌─────────────┐ ┌──────────────────┐ │
│ │ Docker CLI │──▶│ Docker Daemon │ │
│ └─────────────┘ │ (dockerd) │ │
│ └────────┬─────────┘ │
│ │ │
│ ┌──────────────────┼──────┐ │
│ │ Containers │ │ │
│ │ ┌───────┐ ┌───────┐ │ │
│ │ │ App A │ │ App B │ │ │
│ │ └───────┘ └───────┘ │ │
│ └──────────────────────────┘ │
└─────────────────────────────────────────┘
1# Pull and run an nginx web server
2docker run -d -p 8080:80 --name my-nginx nginx
3
4# Visit http://localhost:8080 to see it running
5
6# List running containers
7docker ps
8
9# Stop & remove
10docker stop my-nginx
11docker rm my-nginxA Dockerfile is the blueprint for your container image:
1# Start from an official Node.js image
2FROM node:20-alpine
3
4# Set the working directory
5WORKDIR /app
6
7# Copy and install dependencies first (for layer caching)
8COPY package*.json ./
9RUN npm ci --only=production
10
11# Copy app code
12COPY . .
13
14# Expose the port your app listens on
15EXPOSE 3000
16
17# Start the app
18CMD ["node", "server.js"]1# Build the image
2docker build -t my-app:1.0 .
3
4# Run it
5docker run -p 3000:3000 my-app:1.0Understanding these basics unlocks the entire DevOps ecosystem. Let's go deeper! 🐳