Assembling Your Party of Creatures
Concept:
Docker Compose lets you define and run multi-container applications in a single YAML file. Instead of running multiple 'docker run' commands, you describe all services in docker-compose.yml and start everything with 'docker compose up'. Services can communicate by name. Real-world use: a Java web app with a DB2 database — all defined in one file, started with one command.
Old Wizard Dockerus:
You have learned to summon individual creatures. But real quests require a PARTY — multiple creatures working together!
Apprentice:
Like a web server creature and a DB2 database creature fighting side by side?
Old Wizard Dockerus:
Exactly! But summoning them one by one is tedious and error-prone. That's why the ancient wizards created the Compose Scroll — a single enchanted document that describes your entire party.
Apprentice:
One scroll to summon them all?
Old Wizard Dockerus:
Indeed! In this scroll, each creature is a 'service' with its own section. You declare its blueprint (image), its bridges (ports), its treasure chests (volumes), and its enchanted properties (environment variables).
Apprentice:
And they can talk to each other?
Old Wizard Dockerus:
Yes! Docker Compose creates a magical network where creatures can find each other by name. The web creature simply says 'db' and the database creature answers. No complicated spells needed.
Apprentice:
This is how real applications work in the wild, isn't it?
Old Wizard Dockerus:
Indeed it is. Every enterprise application — a web server, a DB2 database, perhaps a cache — all running as a party. Now write your first Compose scroll: a web creature and a DB2 creature, united!
Example Code:
services:
web:
image: nginx
ports:
- "8080:80"
db:
image: ibmcom/db2
environment:
DB2INST1_PASSWORD: secret
LICENSE: accept
volumes:
- db2data:/database
volumes:
db2data:
Your Assignment
Write a docker-compose.yml with two services: 'web' using the nginx image with port 8080:80, and 'db' using the ibmcom/db2 image with environment variables DB2INST1_PASSWORD set to 'secret' and LICENSE set to 'accept'.
Docker Console