⚡ ~/naveed Interview Prep
⚡ Portfolio Home ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 998+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
Staff SRE / Principal Architect [L3] Docker Staff SRE Scenario [L3]

Q: Your Docker Compose app needs to wait for a database to be ready before starting the app container. How do you implement this?

depends_on only waits for container start, not for the service inside to be ready.

#Docker #Docker #L3 #Containers #Linux
🎙️ Candidate Opening & Architectural Context
""During an image optimization initiative across our services, we solved this exact problem. When addressing this question, I walk the interviewer through our production incident runbook: isolating the blast radius, checking diagnostic logs and metrics, and applying a safe fix.""
Advertisement

🛠️ Production Runbook & Step-by-Step Resolution

1️⃣

Initial Diagnostics & Root Cause Analysis

depends_on only waits for container start, not for the service inside to be ready.

  • wait-for-it.sh — shell script that polls the DB port until it responds.
  • healthcheck + depends_on condition:
2️⃣

Remediation & Permanent Safeguards

Solutions: service_healthy waits for the healthcheck to pass before starting the app.

db:
  image: postgres
  healthcheck:
    test: ["CMD-SHELL", "pg_isready -U postgres"]
    interval: 5s

app:
  depends_on:
    db:
      condition: service_healthy
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: wait-for-it.sh — shell script that polls the DB port until it responds.."
⚡ 60-Second Elevator Pitch Talking Points
  • wait-for-it.sh — shell script that polls the DB port until it responds.
  • healthcheck + depends_on condition:
Advertisement
Want more Docker scenarios?
Explore our complete collection of scenario-based Docker interview runbooks.
Browse All Docker Questions →

📚 Related Production Scenarios in Docker