Skip to content

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 Container Logs That Go Silent Because the App Writes to a File Instead of stdout

- 04.10.26 - ErcanOPAK

🐳 The Container That Was Logging Everything, Just Not Where Docker Could See It

docker logs only ever shows what a container’s main process writes to stdout and stderr, because that’s the one stream Docker’s logging driver actually captures – it has no visibility into arbitrary files a process decides to write on its own. An application (or a framework default, like many logging libraries that write to a local log file unless explicitly configured otherwise) that logs to /app/logs/app.log inside the container is logging correctly and completely, from its own point of view, while docker logs for that same container shows nothing at all, because nothing was ever written to the one place it’s watching.

🔎 The Problem

# The application's logging config (outside the Dockerfile, but
# this is the root cause) defaults to a file sink:
#   logging:
#     file: /app/logs/app.log

# The container runs fine, the app works, but:
docker logs my-container
# (nothing - or only a startup banner printed once at launch)

# Meanwhile, inside the container, the file is filling up normally:
docker exec my-container tail -f /app/logs/app.log
# Shows every log line, perfectly - just never surfaced to `docker
# logs`, `docker-compose logs`, or whatever log aggregator is
# configured to collect from the container's captured streams.

✅ Fix: Point the Application’s Logging at stdout/stderr Inside the Container

  • Change the application’s logging configuration to write to stdout (and errors to stderr) when running inside a container, rather than to a file path – most logging frameworks support this as a simple sink/handler change.
  • If the application genuinely can’t be reconfigured, symlink its log file path to /dev/stdout (and the error log to /dev/stderr) inside the Dockerfile, which redirects file writes into the streams Docker actually captures.
  • Treat ‘logs to stdout, not to a file’ as a standard requirement for anything you containerize going forward, since it’s what lets docker logs, log aggregators, and orchestration platforms all see the same output with no extra plumbing.

⚠️ Why This Is Easy to Miss

  • The application itself is working completely correctly and logging exactly as configured – there’s no bug in the app, which makes ‘docker logs shows nothing’ look like a Docker problem rather than an application logging-destination mismatch.
  • It often only becomes visible once you move from local development (where someone’s tailing the file directly) to a production or staging setup relying on docker logs or an aggregator pulling from the container’s captured streams.

Docker never promised to watch your filesystem – it only ever promised to watch one pipe, and a log file was never connected to it.

— DevOps Engineer

Related posts:

Docker: Use Swarm for Container Orchestration

Docker: Dockerfile Best Practices for Smaller, Faster Images

Docker: Volumes vs Bind Mounts for Persistent Data Storage

Post Views: 1

Post navigation

WordPress: Fix a Multisite Network Where New Subsites Keep Inheriting the Wrong Default Theme
Git: Fix a Reflog Entry That Expires Before You Can Use It to Recover a Lost Commit

Leave a Reply Cancel reply

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

October 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Sep    

Most Viewed Posts

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

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps
  • Photoshop: Fix a Color Profile Mismatch That Makes Printed Output Look Nothing Like What You Saw On Screen
  • WordPress: Fix Search Results That Return Pages From a Theme You Deactivated Months Ago
  • Visual Studio: Fix a Test Project That Builds Fine Alone but Fails to Discover Any Tests After a NuGet Restore
  • ASP.NET Core: Fix a File Upload That Times Out on Slow Connections Only Because Kestrel’s Minimum Data Rate Feature Kicked In
  • JavaScript: Fix an Array Destructuring Default Value That Silently Never Applies Because null Was Passed Instead of Undefined

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (948)
  • How to add default value for Entity Framework migrations for DateTime and Bool (938)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (836)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps

Social

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