|
| 1 | +# Day 33 – Docker Compose: Multi-Container Basics |
| 2 | + |
| 3 | +## Task |
| 4 | +Today's goal is to **run multi-container applications with a single command**. |
| 5 | + |
| 6 | +Yesterday you manually created networks and volumes and ran containers one by one. Docker Compose does all of that in one YAML file. |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## Expected Output |
| 11 | +- A markdown file: `day-33-compose.md` |
| 12 | +- All `docker-compose.yml` files you create |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## Challenge Tasks |
| 17 | + |
| 18 | +### Task 1: Install & Verify |
| 19 | +1. Check if Docker Compose is available on your machine |
| 20 | +2. Verify the version |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +### Task 2: Your First Compose File |
| 25 | +1. Create a folder `compose-basics` |
| 26 | +2. Write a `docker-compose.yml` that runs a single **Nginx** container with port mapping |
| 27 | +3. Start it with `docker compose up` |
| 28 | +4. Access it in your browser |
| 29 | +5. Stop it with `docker compose down` |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +### Task 3: Two-Container Setup |
| 34 | +Write a `docker-compose.yml` that runs: |
| 35 | +- A **WordPress** container |
| 36 | +- A **MySQL** container |
| 37 | + |
| 38 | +They should: |
| 39 | +- Be on the same network (Compose does this automatically) |
| 40 | +- MySQL should have a named volume for data persistence |
| 41 | +- WordPress should connect to MySQL using the service name |
| 42 | + |
| 43 | +Start it, access WordPress in your browser, and set it up. |
| 44 | + |
| 45 | +**Verify:** Stop and restart with `docker compose down` and `docker compose up` — is your WordPress data still there? |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +### Task 4: Compose Commands |
| 50 | +Practice and document these: |
| 51 | +1. Start services in **detached mode** |
| 52 | +2. View running services |
| 53 | +3. View **logs** of all services |
| 54 | +4. View logs of a **specific** service |
| 55 | +5. **Stop** services without removing |
| 56 | +6. **Remove** everything (containers, networks) |
| 57 | +7. **Rebuild** images if you make a change |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +### Task 5: Environment Variables |
| 62 | +1. Add environment variables directly in your `docker-compose.yml` |
| 63 | +2. Create a `.env` file and reference variables from it in your compose file |
| 64 | +3. Verify the variables are being picked up |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +## Hints |
| 69 | +- Start: `docker compose up -d` |
| 70 | +- Stop: `docker compose down` |
| 71 | +- Logs: `docker compose logs -f` |
| 72 | +- Compose creates a default network for all services automatically |
| 73 | +- Service names in compose are the DNS names containers use to talk to each other |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +## Submission |
| 78 | +1. Add your compose files and `day-33-compose.md` to `2026/day-33/` |
| 79 | +2. Commit and push to your fork |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## Learn in Public |
| 84 | +Share your WordPress + MySQL running via Compose on LinkedIn. |
| 85 | + |
| 86 | +`#90DaysOfDevOps` `#DevOpsKaJosh` `#TrainWithShubham` |
| 87 | + |
| 88 | +Happy Learning! |
| 89 | +**TrainWithShubham** |
0 commit comments