🐳 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.
