Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Docker

Docker: Fix a Healthcheck Marking a Container Unhealthy Too Soon

- 18.11.26 - ErcanOPAK

🐳 Docker: Fix a Healthcheck Marking a Container Unhealthy Too Soon

A Docker HEALTHCHECK runs on a fixed interval starting from the moment the container starts, and every failed probe counts toward the unhealthy threshold unless a start period is configured. An application that genuinely needs real startup time — warming a cache, running migrations, waiting on a dependency — will fail every probe during that window, and without a start period those early, expected failures count exactly the same as a probe failing after the app should have been ready.

🔎 The Problem

HEALTHCHECK --interval=5s --timeout=3s --retries=3 \
  CMD curl -f http://localhost:8080/ready || exit 1

# App takes ~20s to finish startup work.
# No --start-period set -> default is 0s.
# 3 failed probes x 5s interval = unhealthy at 15s, before the app is ready.

✅ Fix: Give Startup Its Own Grace Period

  • Set --health-start-period (or start_period in Compose) to comfortably cover real startup time, not just the happy-path average — a cold cache or a slow dependency can both push this out.
  • Point the health check at an endpoint that only returns success once the app is actually serving real traffic, not one that returns 200 the instant the process is alive but before it’s finished initializing.
  • Watch docker inspect‘s health status log during a realistic startup to confirm failures stop landing once the start period is in effect, instead of just assuming the new value is long enough.

🚨 Why This Is Dangerous

  • An orchestrator that restarts a container the moment it’s marked unhealthy can get stuck in a restart loop where the app never survives long enough to finish its own startup work, each restart resetting the clock right back to zero.

A health check that can’t tell ‘still starting’ from ‘actually broken’ will eventually punish an app for the one thing every app has to do once: start up.

— DevOps Engineer

Related posts:

Docker: Centralized Logging Pipeline for Production Containers

Docker: Centralized Logging Pipeline for Production Containers

Docker: Use Container Logging for Debugging

Docker: Use Container Logging for Debugging

Docker: Optimize Images with Dockerfile Best Practices

Docker: Optimize Images with Dockerfile Best Practices

Views: 3

Post navigation

Windows 11: Fix Voice Typing Placing Punctuation in the Wrong Spot
WordPress: Fix a Custom Field Resetting After Every Autosave

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,056)
  • Get the User Name and Domain Name from an Email Address in SQL (982)
  • How to add default value for Entity Framework migrations for DateTime and Bool (980)
  • Get the First and Last Word from a String or Sentence in SQL (859)
  • How to select distinct rows in a datatable in C# (856)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (657)
  • Add Constraint to SQL Table to ensure email contains @ (612)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (548)
  • Find numbers with more than two decimal places in SQL (477)

Recent Posts

  • HTML5: Fix a datalist Suggestion List Not Filtering as You Type
  • WordPress: Fix a Custom Field Resetting After Every Autosave
  • Docker: Fix a Healthcheck Marking a Container Unhealthy Too Soon
  • Windows 11: Fix Voice Typing Placing Punctuation in the Wrong Spot
  • Git: Fix a Stash Pop Conflicting With Unrelated Untracked Files
  • Photoshop: Fix the History Brush Reverting Past a Resize Step
  • SQL Server: Fix a View Returning Stale Data After a Schema Change
  • CSS: Fix an aspect-ratio Box Collapsing When Content Overflows
  • Photoshop: Fix the Color Picker Clamping a Custom Swatch’s Hue
  • JavaScript: Fix Array.sort Reordering Equal Items Unexpectedly

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,056)
  • Get the User Name and Domain Name from an Email Address in SQL (982)
  • How to add default value for Entity Framework migrations for DateTime and Bool (980)
  • Get the First and Last Word from a String or Sentence in SQL (859)
  • How to select distinct rows in a datatable in C# (856)

Recent Posts

  • HTML5: Fix a datalist Suggestion List Not Filtering as You Type
  • WordPress: Fix a Custom Field Resetting After Every Autosave
  • Docker: Fix a Healthcheck Marking a Container Unhealthy Too Soon
  • Windows 11: Fix Voice Typing Placing Punctuation in the Wrong Spot
  • Git: Fix a Stash Pop Conflicting With Unrelated Untracked Files

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com