Docker Basics

Lesson 5 of 6

Treasure Chests and Tower Windows

Concept:

Containers are ephemeral — when they stop, their data is gone. Volumes (-v) persist data outside the container. Port mapping (-p) connects container ports to your machine: '-p 8080:80' means 'my port 8080 → container port 80'. Real-world use: run a DB2 database with persistent storage, or expose your Java web app to the browser.
Old Wizard Dockerus: There is something you must understand, apprentice. When a summoned creature vanishes, everything inside it vanishes too. Poof!
Apprentice: Everything? All its data? That's terrible!
Old Wizard Dockerus: Indeed — unless you give it a Treasure Chest! A volume is a magic chest that exists outside the creature. When the creature stores gems inside — say, your DB2 database — the chest keeps them safe even after the creature is gone.
Apprentice: So the next creature can open the same chest and find all the database records?
Old Wizard Dockerus: Precisely! '-v db2data:/database' means 'attach the chest called db2data to the creature's database room.' Now for ports — remember EXPOSE opened a window inside the tower? Port mapping builds a bridge FROM your castle to that window.
Apprentice: A bridge from my world to the creature's world?
Old Wizard Dockerus: Yes! '-p 8080:80' means 'build a bridge from your castle gate 8080 to the creature's window 80.' Visitors knock on YOUR gate, and the bridge takes them to the creature. You could run a whole web server or a DB2 database this way!
Apprentice: Treasure chests for data, bridges for connections. I love this magic!
Old Wizard Dockerus: Now summon an nginx creature with a bridge — detached, so it runs in the background while you continue your studies.
Example Code:
docker run -d -p 8080:80 nginx
docker run -d -v db2data:/database -p 50000:50000 ibmcom/db2

Your Assignment

Run an nginx container in detached mode (-d) with port 8080 mapped to container port 80.

Docker Console
docker>