Learn 🧠 All Concepts (20) 🤖 What is an LLM? 📚 RAG Explained ⚡ AI Agents 💻 Run AI Locally 🇮🇳 AI in India 📖 Learn Tracks 🔧 DevOps Track ⚙️ AI Ops Track 🗺️ AI Engineer Roadmap
Tools 🔧 AI Tools Directory 🔓 Open Source AI ⭐ Top GitHub Repos ✦ Claude Skill Repos 🚀 Ready-to-Deploy Projects
Build 🏗️ Build Hub 🎯 Master Prompts 🧩 RAG Agents 🚀 App Megaprompts
Workflows ⚡ All Workflows (22) 🎥 Text to Video 🎞️ Image to Video 🔊 Text to Speech ♻️ Automation
Resources 🧪 Colab Notebooks ⚙️ n8n Workflows 📈 Algo Trading 💰 Passive Income
🗂️ Browse All Topics About AItheGuru
Learn DevOps Priya packs her app in a box
DevOps Ch 3 / 10 Intermediate
📦

Priya packs her app in a box

Docker, containers, and why "it works on my machine" is no longer acceptable

⏱ 12 min 6 commands 4 takeaways
📦
In this chapter
Priya
Backend developer in Bangalore
The story

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:
  - db

db:

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.

Key takeaways

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

Commands from this chapter
$ docker build -t name .
Build an image from Dockerfile
$ docker run -p 8080:8080 name
Run container and map ports
$ docker ps
List running containers
$ docker stop container-id
Stop a running container
$ docker compose up -d
Start all services in background
$ docker compose down
Stop and remove all services