Skip to main content

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 MachineContainer
IncludesFull OS + appApp + libraries only
SizeGBsMBs
StartupMinutesSeconds
IsolationHardware-levelProcess-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)
  1. You write a Dockerfile describing your environment
  2. docker build executes the instructions and produces an image
  3. docker run starts a container from that image
  4. 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.