What is Docker?
The Problem Docker Solves
Imagine you build a Node.js app on your machine. It works perfectly. You send it to a teammate — they're on a different OS, have a different Node version, and suddenly it breaks. You've seen "works on my machine" turn into hours of debugging.
Docker solves this by packaging your app and its entire environment into a container that runs identically everywhere.
Containers vs. Virtual Machines
Both containers and VMs isolate applications, but they do it very differently.
| Virtual Machine | Container | |
|---|---|---|
| Includes | Full OS + app | App + libraries only |
| Size | GBs | MBs |
| Startup | Minutes | Seconds |
| Isolation | Hardware-level | Process-level |
A VM virtualizes hardware and runs a full guest OS. A container shares the host OS kernel but isolates the process — making containers much lighter and faster.
Core Concepts
Image
An image is a read-only blueprint for a container. It contains the OS base layer, your app's code, dependencies, and startup instructions. Think of it like a class in OOP.
Container
A container is a running instance of an image — like an object instantiated from a class. You can run many containers from the same image simultaneously.
Dockerfile
A Dockerfile is a text file with step-by-step instructions for building an image:
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]
Each line creates a new layer in the image. Docker caches layers, so unchanged steps don't rebuild — making subsequent builds fast.
Docker Hub
Docker Hub is the default public registry for Docker images. When you run docker pull node:20, Docker fetches the official Node.js image from there. You can also push your own images for deployment.
How Docker Works
Dockerfile → docker build → Image → docker run → Container
↑
Docker Hub (pull)
- You write a
Dockerfiledescribing your environment docker buildexecutes the instructions and produces an imagedocker runstarts a container from that image- The container runs your app in an isolated environment
Installing Docker
Download Docker Desktop for your OS:
Verify the installation:
docker --version
docker run hello-world
If you see a "Hello from Docker!" message, you're ready to go.