Lab 3: Container Lifecycle Investigation
Type: Independent exploration
Time: 30-45 minutes
Deliverable: Completed worksheet
Purpose
You've run containers in Labs 1 and 2. Now it's time to really understand how they work.
This lab reinforces container fundamentals through hands-on discovery. No copying from Stack Overflow - you'll learn by experimenting and observing.
What You'll Learn
By completing this investigation, you'll understand:
- Container states: created, running, paused, stopped, exited
- Lifecycle commands: start, stop, restart, pause, kill, rm
- Data persistence: what survives container removal, what doesn't
- Image vs Container: the critical distinction that confuses everyone
- Debugging techniques: how to investigate crashed or misbehaving containers
- Common pitfalls: port conflicts, name collisions, and how to fix them
Instructions for Students
1. Download the Worksheet
Get WORKSHEET.md and save it as YOURNAME-lifecycle-investigation.md
2. Complete Each Section
Work through the questions by running commands and observing results.
Rules:
- Answer in your own words (no copy-paste from docs)
- Include the commands you ran to discover each answer
- Mark surprising discoveries with ๐ก
- It's okay to be wrong - the learning is in figuring out why!
3. Clean Up After Each Section
Don't let containers accumulate. Use:
docker rm -f $(docker ps -aq) 2>/dev/null || true4. Submit Your Completed Worksheet
Save your completed worksheet and submit according to your instructor's directions.
Expected Time Breakdown
| Section | Time |
|---|---|
| Part 1: Container States | 5-10 min |
| Part 2: Data Lifecycle | 5-10 min |
| Part 3: Lifecycle Commands | 5 min |
| Part 4: Image-Container Relationship | 10 min |
| Part 5: Real-World Debugging | 5-10 min |
| Part 6: Troubleshooting | 5 min |
| Total | 30-45 min |
Tips for Success
Don't Just Read - Experiment!
โ Bad approach:
- Read the question
- Google the answer
- Write it down
โ Good approach:
- Read the question
- Form a hypothesis ("I think X will happen because...")
- Run commands to test it
- Observe what actually happens
- Explain the result in your own words
Use --help Liberally
docker --help
docker ps --help
docker run --help
docker inspect --helpThe documentation is built-in!
Try Things That Might "Break"
You're in a safe environment. The worst that happens is:
docker rm -f $(docker ps -aq) # Delete all containers
docker system prune -f # Clean upThen start fresh. Breaking things teaches you how they work.
Keep a Terminal Log
Consider using script to record your session:
script ~/lifecycle-investigation.log
# Do your work
# Ctrl+D to stop recordingThis captures everything you tried - useful for reflection!
Common Questions
"How do I know if my answer is right?"
If your commands demonstrate the concept and your reasoning makes sense, you're on the right track. There's often more than one way to discover the same truth.
"Can I work with a partner?"
You can discuss approaches, but each person must run the commands and write answers in their own words.
"What if I get stuck?"
- Try
--helpon the command - Try variations and see what happens
- Check
docker ps -ato see container states - Use
docker inspectto see details - Ask in the class forum with what you've tried
"This is taking longer than 45 minutes!"
That's okay. This is exploration, not a race. The goal is deep understanding, not speed.
Assessment
Your submission will be evaluated on:
- Experimentation evidence: Did you actually run commands?
- Understanding: Can you explain concepts in your own words?
- Insight: Did you discover the "why" behind the behavior?
- Completeness: Did you attempt all sections?
Not evaluated on:
- Speed
- Getting every answer "right" on the first try
- Having the same answers as other students
After You Finish
Reflect on Key Insights
- What's the #1 thing you learned about containers?
- What misconception did you have before this lab?
- How will this knowledge help you in future labs?
Preview: Why This Matters
Week 3 (Compose): You'll run multi-container applications. Understanding lifecycle is crucial when services depend on each other.
Week 4 (Kubernetes): K8s manages container lifecycle automatically. Understanding these fundamentals helps you debug pod failures.
Production: Knowing the difference between stop/start vs rm/run can mean the difference between preserving logs for debugging and losing them forever.
Files
WORKSHEET.md- The questions you'll answer (download this!)SOLUTION_KEY.md- Instructor reference with expected answers and teaching notes (don't peek!)README.md- This file
Need Help?
- Stuck on a command? Try
docker COMMAND --help - Container won't behave? Use
docker inspectto see its full state - Made a mess?
docker rm -f $(docker ps -aq)to reset - Still stuck? Post in the class forum with:
- The question you're on
- The commands you've tried
- What you expected vs what happened
Final Cleanup
After completing the worksheet:
# Remove all containers
docker rm -f $(docker ps -aq)
# Clean up system
docker system prune -f
# Verify
docker ps -a # Should be emptyGood luck! Remember: the learning is in the experimentation, not in getting perfect answers.
๐ณ Happy container exploring! ๐ณ
