Skip to content

Docker Container Logs Not Showing Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Docker Container Logs Not Showing Fix. We cover key concepts, practical examples, and best practices.

You run docker logs my-container and get nothing, even though the container is running. Docker captures container logs from stdout and stderr, so when logs are missing the issue is usually the logging driver, the application not writing to stdout, or a log configuration mismatch.

The Problem

docker logs my-app
# (no output)

The container runs fine but logs show nothing. Check the container status:

docker ps -a --filter name=my-app

Expected:

CONTAINER ID   IMAGE     STATUS         PORTS   NAMES
abc123         my-app    Up 10 minutes          my-app

Wrong Code (Application Not Writing to stdout)

import logging

# WRONG — logs to file, never seen by Docker
logging.basicConfig(filename='/var/log/app.log', level=logging.INFO)
logging.info('Application started')

Right Code (Writing to stdout)

import logging
import sys

# RIGHT — Docker captures stdout
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.info('Application started')

Expected output:

INFO:root:Application started

Step-by-Step Fix

Step 1: Check the log driver

docker inspect my-app --format '{{.HostConfig.LogConfig.Type}}'

Expected output:

json-file

If it shows none or journald, logs are not stored where docker logs reads them.

Step 2: Switch to json-file driver

Edit /etc/docker/daemon.json:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

Restart Docker:

sudo systemctl restart docker

Step 3: Verify stdout/stderr in your application

import sys

# Docker captures anything written to stdout/stderr
sys.stdout.write('This appears in docker logs\n')
sys.stderr.write('Errors also appear\n')

For Node.js:

// WRONG — file logging
const fs = require('fs');
fs.appendFileSync('/app/logs.txt', 'message');

// RIGHT — console.log writes to stdout
console.log('message');

Step 4: Test with a simple container

docker run --rm alpine echo "hello world"
docker ps -l -q | xargs docker logs

Expected:

hello world

Step 5: Check Docker daemon logs

sudo journalctl -u docker -n 50 --no-pager

Prevention Tips

  • Always write application logs to stdout/stderr, not files
  • Configure log rotation with --log-opt max-size=10m
  • Use the json-file log driver unless you have a specific reason not to
  • Test log output with docker logs --tail 10 immediately after starting
  • Monitor log storage with docker system df

Common Mistakes with container logs

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world DOCKER code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does docker logs show nothing if the container is running?

The container uses a non-json-file log driver (like journald or none), or the application writes logs to files instead of stdout/stderr. Run docker inspect to check the log driver and verify your app uses stdout.

How do I change the log driver for a running container?

You cannot change the log driver on a running container. Stop the container, remove it, and recreate it with --log-driver json-file. To make the change permanent for all containers, edit /etc/docker/daemon.json and restart Docker.

Do Docker containers store logs persistently?

By default logs are stored as JSON files on the host in /var/lib/docker/containers/<id>/<id>-json.log. They persist across container restarts but are lost when the container is removed unless you configure a remote logging driver like syslog or awslogs.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro