DevOps • Infrastructure

What Is Docker?

Learn how containers package your app with everything it needs to run anywhere — from your laptop to the cloud.

Scroll to start

What Is a Container?

A container is a lightweight, self-contained package that holds everything your software needs to run: the code, its dependencies, and the runtime environment. It runs in isolation from the rest of the system — meaning it works exactly the same whether it is on your laptop, a server, or in the cloud.

Think of it like a shipping container. A shipping container carries goods in a standardized box — no matter what is inside, the container itself is always the same shape and size. Docker containers work the same way for software.

Without Containers

  • "It works on my machine" — broken on production
  • Manual installation of dependencies on every server
  • Version conflicts between apps sharing the same machine
  • Deployments take days to configure

With Containers

  • Runs identically everywhere Docker is installed
  • One command spins up the entire environment
  • Each app isolated in its own container
  • Deploy in minutes, not days

Containers vs Virtual Machines

Before containers, virtual machines (VMs) were how you隔离 software. A VM simulates an entire computer — complete operating system, all the overhead. Containers are lighter — they share the host OS kernel and only package the app + its dependencies. Faster to start, smaller to store.

Key Analogy

If your code were an apartment building, a VM would be a building with separate houses — each with its own plumbing and electricity. A container is an apartment — shared infrastructure, but your own locked door and private space inside.

Container vs VM
🏠
VM
Full OS, heavy, slow to start
vs
📦
Container
Shared OS, lightweight, starts in seconds

Netflix, Google, and Amazon all run on containers at massive scale. The ability to deploy quickly and reliably is what separates hobby projects from production systems.

The Dockerfile — Your App's Blueprint

A Dockerfile is a recipe for building your container. It lists the base image, installs dependencies, copies your code, and tells Docker how to run it.

01
🖼️

Base Image

Starts from an existing image — like a stripped-down Linux OS with Node or Python pre-installed. You never start from scratch.

02
📥

Dependencies

Install everything your app needs — npm packages, Python libraries, system tools. These are bundled into the image.

03
🚀

Run Command

The final instruction tells Docker what command to run when the container starts — usually your app's entry point.

Dockerfile
# Start from a Node.js base image
FROM node:20-alpine

# Set the working directory
WORKDIR /app

# Copy package files and install dependencies
COPY package*.json ./
RUN npm install

# Copy your application code
COPY . .

# Tell Docker to run this when the container starts
CMD ["node", "index.js"]

From Code to Container

Here is the full workflow for containerizing a simple web app and running it anywhere with two commands.

terminal
# Build the container image from the Dockerfile
docker build -t my-web-app .

# Run the container (opens port 3000)
docker run -p 3000:3000 my-web-app

Share Your Container

Docker Hub is like GitHub for containers. Push your image there and anyone can pull it and run your app in seconds — no installation instructions needed. Just one command: docker run yourname/app.

Knowledge Check

Test what you learned about Docker and containers.

3 Questions

Question 01

What is the main advantage of a container over a virtual machine?

Question 02

What is a Dockerfile?

Question 03

Why does Docker solve the "works on my machine" problem?

🏆

You crushed it!

Perfect score on Docker and Containers.