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 Container Stuck in a Tight Restart Loop With Nothing Ever Printed in docker logs Because the Entrypoint Script Crashes Before Its Output Buffer Gets Flushed to Stdout

- 11.11.26 - ErcanOPAK

🐳 Docker: Fix a Container Stuck in a Tight Restart Loop With Nothing Ever Printed in docker logs Because the Entrypoint Script Crashes Before Its Output Buffer Gets Flushed to Stdout

Docker captures whatever a container’s PID 1 process writes to stdout and stderr, but a process that buffers its output — many scripting language runtimes default to fully buffering stdout when it isn’t connected to an interactive terminal — only hands that text to the OS, and therefore to Docker’s log driver, when the buffer is explicitly flushed or the process exits cleanly. An entrypoint that crashes hard before that flush happens loses every line it had written so far, so docker logs shows a completely empty output for a container that’s visibly crash-looping.

🔎 The Problem

$ docker logs flaky-container
(empty output)

$ docker inspect flaky-container --format '{{.State.ExitCode}}'
139   <- SIGSEGV, process terminated abnormally before its stdout buffer flushed

$ docker run -it --entrypoint sh flaky-container  # ran interactively instead
Loading config...
Connecting to database...
Segmentation fault (core dumped)   <- the output was always there, just never flushed to the log driver

✅ Fix: Stop Buffering, and Reproduce the Crash Interactively

  • Run the entrypoint with its runtime’s output buffering disabled for non-interactive stdout (for example PYTHONUNBUFFERED=1 for Python, or explicitly flushing after each write) so lines are handed to Docker’s log driver as they’re written instead of waiting in a buffer a crash can discard.
  • If the entrypoint is a shell script wrapping another process, exec the real process as the last line instead of running it as a backgrounded or piped child, so it becomes PID 1 directly and its own output and exit code aren’t lost behind a wrapper that can swallow both.
  • Reproduce the crash by running the image interactively (docker run -it --entrypoint sh <image>, then launching the real command by hand) so the crash’s actual output lands on your terminal in real time, independent of whatever buffering affects the detached container’s log driver.

🚨 Why This Is Dangerous

An empty docker logs output on a crash-looping container is easy to misread as “the container never even started,” sending you to check image builds, registry pulls or scheduler configuration instead of the actual crash that logs would have shown if it had ever been flushed.

Docker can only log what the process actually hands to stdout — a crash that happens before a flush doesn’t produce an empty log because nothing went wrong, it produces one because the evidence never left the buffer.

— DevOps Engineer

Related posts:

Docker: Use .dockerignore to Reduce Build Context and Speed Up Builds

Docker: Use .dockerignore to Reduce Build Context and Speed Up Builds

Docker: Fix a Published Port That Still Refuses Connections From the Host

Docker: Fix a Published Port That Still Refuses Connections From the Host

Why Your Docker Image Is Slow Even Though It’s “Small”

Why Your Docker Image Is Slow Even Though It’s “Small”

Views: 5

Post navigation

Photoshop: Fix Content-Aware Fill Producing an Obviously Repeating Tiled Pattern Because the Sampling Area You Left Selected Is Too Thin and Repetitive for the Algorithm to Draw From
Visual Studio: Fix CodeLens Reference Counts Staying at Zero for an Entire Solution Because the Local CodeIndex Cache Under %LocalAppData% Never Finished Its Initial Build

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,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (857)
  • How to select distinct rows in a datatable in C# (853)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (608)
  • 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 (546)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

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