Priya packs her app in a box
Docker, containers, and why "it works on my machine" is no longer acceptable
Priya had built a beautiful Flask API. It worked perfectly on her MacBook. She sent the code to the deployment server. Her colleague Rahul tried to run it. It crashed immediately.
"But it works on my machine!" Priya said.
"Your machine has Python 3.11, certain libraries, specific environment variables, and macOS. The server has Python 3.8, different libraries, and Ubuntu," said Rahul.
This is the most famous problem in software. Docker was built to solve it entirely.
What is Docker?
Docker lets you pack your application and everything it needs — the code, the Python version, the libraries, the configuration — into one portable box called a container.
You ship the box. The box runs anywhere. The "works on my machine" problem disappears because you're shipping the machine.
Think of it like this: instead of giving someone a recipe and hoping they have the right ingredients, you give them a complete tiffin box — everything already prepared, ready to eat.
The key concepts
Dockerfile — the recipe. Instructions for building your container.
Image — the cooked meal. A built, ready-to-use snapshot of your app.
Container — the meal being eaten. A running instance of your image.
You write a Dockerfile once. Build it into an Image. Run it as many Containers as you need.
Priya's Dockerfile
```dockerfile
Start from official Python image
FROM python:3.11-slim
Set working directory inside container
WORKDIR /app
Copy requirements first (for caching)
COPY requirements.txt .
Install dependencies
RUN pip install -r requirements.txt
Copy rest of the code
COPY . .
Tell Docker what port the app uses
EXPOSE 5000
Command to start the app
CMD ["python", "app.py"]
```
Build and run
```bash
Build an image from the Dockerfile
docker build -t priya-api .
Run the container
docker run -p 5000:5000 priya-api
See running containers
docker ps
Stop a container
docker stop container-id
```
The `-p 5000:5000` maps port 5000 on your laptop to port 5000 inside the container. Without this, the container runs but you can't reach it.
Docker Compose — running multiple boxes together
Real apps have multiple services — a web server, a database, a cache. Docker Compose lets you define and run all of them together.
```yaml
docker-compose.yml
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
depends_on:
- dbdb:
image: postgres:15
environment:
POSTGRES_PASSWORD: secret
POSTGRES_DB: myapp```
```bash
Start everything
docker compose up
Start in background
docker compose up -d
Stop everything
docker compose down
```
One command starts your entire application stack. Rahul can run the exact same setup on his Windows PC without changing a single thing.
What Priya learned
She now builds a Docker image as part of every project. She never has environment conversations with colleagues. Deployments became predictable — if it runs in Docker locally, it runs in Docker on the server. Same container, same result, every time.
The box travels. The contents stay consistent.
Docker packages your app + its environment into a portable container
Dockerfile is the recipe, Image is the built package, Container is the running app
docker build creates an image, docker run starts a container
Docker Compose manages multi-service applications with one command