Modern DevOps

Docker &
nginx

Why "it works on my machine" killed careers. What containers actually are. And how nginx quietly powers a third of the internet.

Sections

7

Read time

25 min

Level

Beginner

The Problem Docker Solves

Every developer has said this at least once. You build an app on your Mac, it works perfectly. You send it to a colleague or deploy it to a server β€” and it immediately crashes.

Your Mac πŸ’»

Python 3.11 βœ“

Library A version 2.0 βœ“

Library B version 5.1 βœ“

App works perfectly βœ“

Your server πŸ–₯️

Python 3.8 ← different version!

Library A version 1.5 ← old version!

Library B not installed ← missing!

App crashes πŸ’₯

β€œIt works on my machine!”

β€” every developer, at least once

Docker solves this completely by packaging your app and everything it needs into a single portable box called a container.

πŸ’‘

Key Takeaway

Docker doesn't fix your code β€” it eliminates environment differences. Same container, same behavior, everywhere.

What is Docker?

Docker packages your app and all its dependencies into a container β€” a self-contained box that runs identically on any machine.

What's inside a container:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚ CONTAINER β”‚

β”‚ β”‚

β”‚ Your app β”‚

β”‚ Python 3.11 β”‚

β”‚ Library A 2.0 β”‚

β”‚ Library B 5.1 β”‚

β”‚ All config files β”‚

β”‚ β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Your Mac β†’ runs βœ“

Friend's PC β†’ runs βœ“

Ubuntu server β†’ runs βœ“

AWS cloud β†’ runs βœ“

Where Docker Hub comes in

Docker Hub is like GitHub but for Docker images. Thousands of ready-made images you can use instantly:

ubuntu

Bare Ubuntu system

nginx

Web server, ready

postgres

Full PostgreSQL DB

python

Python + pip

node

Node.js ready

redis

Cache DB

mysql

MySQL database

alpine

Tiny Linux base

Containers vs Virtual Machines

You already use a VM (your Ubuntu server). How is a Docker container different?

Virtual Machine

A full house with its own kitchen

Your Mac hardware

└── UTM (hypervisor)

└── Full Ubuntu OS

β”œβ”€β”€ kernel, drivers

└── your app

Heavy β€” full OS inside

Minutes to start, GBs of RAM

Docker Container

A hotel room β€” shared building

Ubuntu Server

Linux kernel (shared ↔ all containers)

β”œβ”€β”€ Container A: App + libs

β”œβ”€β”€ Container B: App + libs

└── Container C: App + libs

Light β€” no separate OS

Seconds to start, MBs of RAM

πŸ’‘
Think of it this way...
VM = a full house (you own the kitchen, bedroom, bathroom β€” everything duplicated)
Container = a hotel room (shared building infrastructure β€” electricity, plumbing, elevator β€” your own private space inside)

Hotel rooms are faster to set up, cheaper, and you can have 100 of them in one building.
🀯

Did You Know?

Containers start in seconds. A full Ubuntu VM might take 30–60 seconds to boot. This is why microservices (running 50+ small containers) are practical with Docker but impractical with VMs.

Images, Containers & Dockerfile

πŸ“‹

Image

A blueprint β€” like a recipe. Static, read-only. Stored on Docker Hub. From one image you can create 100 identical containers.

πŸ“¦

Container

A running instance made from an image. Like a meal made from a recipe. You can run, stop, restart, delete containers independently.

πŸ“„

Dockerfile

A text file with instructions to build your OWN custom image. Define what OS to start from, what software to install, what files to copy in.

A real Dockerfile

Dockerfile

FROM ubuntu:24.04← start from official Ubuntu image
RUN apt install -y python3← install Python
COPY app.py /app/← copy your app into the container
CMD ["python3", "/app/app.py"]← run this on container start
πŸ’‘

Key Takeaway

Image = recipe. Container = meal. Dockerfile = instructions for writing your own recipe. One image, infinite identical containers.

Docker Commands

The commands you'll use 90% of the time:

docker pull ubuntu

Download the Ubuntu image from Docker Hub

docker run ubuntu

Create and start a container from the ubuntu image

docker run -it ubuntu bash

-it = interactive terminal. Drops you inside the container with a bash shell

docker run -d nginx

-d = detached (runs in background). Start nginx web server in background

docker ps

List all currently running containers

docker ps -a

List ALL containers, including stopped ones

docker stop <id>

Stop a running container (graceful shutdown)

docker rm <id>

Delete a stopped container

docker images

List all images downloaded on your machine

docker logs <id>

See stdout/stderr output from a container

Real-world example

❌ Without Docker

Server 1 β†’ Python 3.8, app v1.0

Server 2 β†’ Python 3.9, app v1.0 ← drift

Server 3 β†’ Python 3.8, app v1.1 ← drift

Nightmare to manage. Every server different.

βœ… With Docker

docker run myapp:v1.0 ← all servers

Identical everywhere, always.

Update β†’ docker run myapp:v1.1

Rollback β†’ docker run myapp:v1.0

What is nginx?

When you type a URL in your browser, something on the server receives your request and sends back the webpage. That "something" is a web server β€” and nginx is one of the most popular ones in the world.

You type google.com

↓

Your browser sends a request to the server

↓

nginx receives the request

↓

nginx finds the right file (HTML, image, etc)

↓

nginx sends it back to your browser

↓

You see the webpage βœ“

Who uses nginx?

NetflixAirbnbGitHubDropboxWordPressCloudflareGitLabUber
🀯

Did You Know?

About 33% of all websites on the internet use nginx. It was built in 2004 specifically because Apache struggled under heavy traffic. nginx handles 10,000+ concurrent connections efficiently where Apache would slow to a crawl.

nginx vs Apache

Apache (1995)

  • β€’ Each request gets its own thread
  • β€’ Gets slow under heavy traffic
  • β€’ More memory per connection
  • β€’ Easier config for beginners

nginx (2004)

  • β€’ Event-driven, non-blocking
  • β€’ Handles thousands of connections
  • β€’ Far less memory
  • β€’ Built for production scale

What nginx Can Do

nginx is far more than a web server. Here are the 4 main roles it plays in production:

πŸ“„
01

Serve Static Files

HTML, CSS, images, JavaScript. User requests index.html β†’ nginx finds it and sends it back. Extremely fast β€” nginx is optimized for this.

πŸ”€
02

Reverse Proxy

Sits in front of your app. Receives all requests β†’ forwards to your app β†’ sends response back. Protects your app from direct internet exposure.

βš–οΈ
03

Load Balancer

Spreads traffic across multiple servers. Server 1 gets request 1, Server 2 gets request 2. No single server gets overwhelmed.

πŸ”’
04

SSL Termination

Handles HTTPS encryption. Your app communicates in plain HTTP internally. nginx handles the security layer β€” the padlock in the browser.

πŸ’‘

Key Takeaway

nginx + Docker is one of the most common production setups in the world. nginx handles incoming traffic and SSL, Docker containers run the actual app. Understanding both makes you dangerous as a DevOps engineer.

Key Concepts Flashcards

Click any card to flip and reveal the definition.

What is Docker?

A tool that packages your app + all its dependencies into a container. The container runs identically on any machine β€” solving 'it works on my machine'.

Image vs Container

Image = the recipe/blueprint (static). Container = a running instance made from the image. Same image β†’ 100 identical containers. Images stored on Docker Hub.

Container vs VM

VM = full OS inside (heavy, minutes to start). Container = shares host kernel (light, seconds to start). Container is like a hotel room, VM is like a full house.

What is a Dockerfile?

A text file with instructions to build your own Docker image: FROM ubuntu, RUN apt install python3, COPY app.py, CMD python3 app.py

What is Docker Hub?

Online registry of Docker images β€” like GitHub for containers. Thousands of ready-made images: ubuntu, nginx, postgres, python, node. Pull with: docker pull nginx

What is nginx?

A high-performance web server used by Netflix, Airbnb, GitHub. Handles ~33% of all websites. Built in 2004 to solve Apache's performance problems under heavy traffic.

What is a reverse proxy?

nginx sitting in front of your app β€” receives all requests, forwards to your app, sends response back. Protects your app from direct internet exposure. Also handles SSL termination.