Skip to main content
InterviewHubPRO
Section Overview
Q45

Question 45 of 50

Part 3: Advanced Internals, Scale & Production Security (Senior / Lead)

90%
Docker & Containers (50 Qs)•Part 3: Advanced Internals, Scale & Production Security (Senior / Lead)

Docker Compose: Production Healthchecks and Startup Dependencies.

senior LevelMost AskedCode ExampleSecurity & AuthDocker & Containers

In Simple Words: Using depends_on: [db] only waits for the database container to start running, not for the database engine to finish initializing!

  • Use Healthchecks with condition: service_healthy to ensure the web service starts only after the database is fully ready to accept client connections:
yaml
services:
  db:
    image: postgres:16-alpine
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

  web:
    build: .
    depends_on:
      db:
        condition: service_healthy # Starts ONLY after pg_isready succeeds!