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
Without Docker:
Dev: Python 3.11 β
Server: Python 3.8 β different!
App crashes π₯
With Docker:
docker run myapp β one command
Your Mac β
Server β
AWS cloud β identical everywhere
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:
ubuntuBare Ubuntu system
nginxWeb server, ready
postgresFull PostgreSQL DB
pythonPython + pip
nodeNode.js ready
redisCache DB
mysqlMySQL database
alpineTiny 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
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?
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
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 ubuntuDownload the Ubuntu image from Docker Hub
docker run ubuntuCreate 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 psList all currently running containers
docker ps -aList ALL containers, including stopped ones
docker stop <id>Stop a running container (graceful shutdown)
docker rm <id>Delete a stopped container
docker imagesList 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?
Did You Know?
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:
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.
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.
Load Balancer
Spreads traffic across multiple servers. Server 1 gets request 1, Server 2 gets request 2. No single server gets overwhelmed.
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.