Logs Metrics & Traces

How to Manage Docker Container Logs

November 28, 2026
7
min read
Logs Metrics & Traces

When a Docker container crashes or starts returning errors, docker logs <container-name-or-id> is often the quickest way to see what happened. It shows the stdout and stderr output Docker can still access, while -f follows new messages, --tail limits the number of lines, and --since narrows the time range. But logs can disappear when a container is removed or older files are rotated, so reading them is only part of managing them.

This guide explains how to inspect and filter logs from individual containers and Docker Compose services, configure logging drivers and rotation, and forward output to a central backend. You’ll also learn how to troubleshoot empty or missing logs and keep the history you need during an investigation.

How to View and Filter Docker Container Logs

When a container fails or starts behaving unexpectedly, its logs are often the first place to investigate. You can use docker logs to inspect messages leading up to a failure, follow new output from a running service, or isolate activity during a particular time window. The key is to narrow the output to the container and period you’re investigating rather than reading its entire log history.

Find a Container and Display Its Logs

Start by identifying the container. Run docker ps to list running containers, or add -a to include containers that have stopped or exited:

docker ps
docker ps -a

Use the name or ID from the output to retrieve its logs. For example, if your container is named my-app, run:

docker logs my-app

You might see output like this:

INFO  Starting server on 0.0.0.0:8080
INFO  Connected to postgres at db:5432
ERROR Failed to load config key PAYMENT_TIMEOUT
INFO  GET /healthz 200 1ms

docker logs displays the available output captured from the container’s stdout and stderr streams. The messages themselves come from the application, so their format and severity labels depend on how it handles logging.

If a container exits unexpectedly, check its final messages for startup failures, missing configuration, or application errors. You can still read logs from an exited container as long as it hasn’t been removed and the output remains accessible through its logging driver.

Follow Logs in Real Time and Show the Last 100 Lines

For a running container, use -f (--follow) to watch new messages as they arrive:

docker logs -f my-app

This is useful when reproducing an error or checking whether a service is still receiving requests. Press Ctrl+C to stop following the output without stopping the container.

By default, docker logs -f can print all retained messages before streaming new ones. On a busy container, that can produce more output than you need. Use --tail to limit the initial results:

docker logs --tail 100 my-app

To display the last 100 lines and continue watching new messages, combine both flags:

docker logs --tail 100 -f my-app

Use --tail when you want the most recent activity, particularly after a container restart or a newly reported error. If you know when the problem began, filtering by time gives you a more precise view.

Filter Docker Logs by Time and Search for Errors

Use --since to retrieve messages generated after a particular time. For example, this command shows available logs from the last ten minutes:

docker logs --since 10m my-app

When investigating an incident with a known start and end time, combine --since and --until to isolate that window:

docker logs --since 2026-11-19T09:00:00Z --until 2026-11-19T09:15:00Z my-app

Both flags accept timestamps and relative durations. Include Z for UTC or an explicit offset such as +03:00 when using timestamps. Without timezone information, Docker interprets them using the client’s local timezone.

Timestamps help you compare container activity with an alert, deployment, or failure reported elsewhere. Add -t (--timestamps) to prefix each log entry with its recorded time:

docker logs -t --tail 3 my-app

For a live investigation, combine the filters to show recent messages with timestamps while continuing to capture new output:

docker logs -f --tail 100 -t --since 10m my-app

You can also search for specific messages using grep in a Unix-like shell. For example, to find lines containing error within the last ten minutes:

docker logs --since 10m my-app 2>&1 | grep -i error

The -i flag makes the search case-insensitive. The 2>&1 redirect ensures stderr is included in the pipe; otherwise, messages written to that stream can bypass grep when the container runs without a TTY.

Remember that grep matches text, not the actual outcome of an operation. An application might report a failure using words such as timeout or failed instead of error, so adjust the search term to match the problem you’re investigating.

View Logs from Multiple Containers with Docker Compose

If your application runs multiple services through Docker Compose, inspecting containers individually can make it harder to follow errors between them. docker compose logs combines their output and identifies the container associated with each message.

Run the command from your Compose project directory:

docker compose logs

The output includes prefixes that identify the source container, helping you distinguish messages from services such as api and db. This is useful when one service reports a connection failure and you need to check what was happening in the service it tried to reach.

To follow only the api service and display its last 100 lines:

docker compose logs -f --tail 100 api

You can pass multiple service names to inspect related services together. If a service has several replicas, --tail applies to each container, and --index lets you select an individual replica. Use --no-log-prefix when you need the log messages without Compose’s container labels.

Where Are Docker Container Logs Stored and How Do You Rotate Them?

Docker’s logging driver determines where container output is stored and how much history remains available. On standalone Docker Engine, the default json-file driver does not rotate logs automatically, so containers generating large amounts of output can fill the host disk. Docker Desktop 4.94.0 and later default to the local driver for newly created Linux containers, which rotates logs automatically. Check the active driver before changing your logging configuration.

Find the Docker Log File Path and Active Logging Driver

Start by checking the Docker daemon’s default logging driver:

docker info --format '{{.LoggingDriver}}'

Then check which driver a specific container uses:

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

The values can differ if a container was created with its own logging configuration or before the daemon’s defaults changed. The container’s configured driver determines how its output is stored.

The three main local logging drivers handle storage differently:

  • json-file: Stores log messages as JSON records containing their timestamps and output streams. Logs are not rotated unless you configure rotation.
  • local: Uses a compact, Docker-managed format with automatic rotation and compression.
  • journald: Sends container output to the host’s systemd journal, where journal retention settings apply.

All three support reading available output through docker logs.

For containers using json-file on Linux, logs are stored under Docker’s data directory, which defaults to:

/var/lib/docker/containers/<id>/<id>-json.log

If Docker uses a different data directory, retrieve the container’s actual log file path with:

docker inspect --format '{{.LogPath}}' my-app

This path is specific to the container’s logging driver and may be empty for other drivers. On Docker Desktop for macOS and Windows, Linux container logs are managed inside a VM, so paths returned by Docker are not necessarily accessible from the host filesystem.

Avoid manually editing, truncating, or deleting Docker-managed log files. Doing so can interfere with logging. Configure rotation instead.

Configure Docker Log Rotation with max-size and max-file

For containers using json-file, configure rotation using two options: max-size controls how large an individual log file can grow, while max-file determines how many files Docker retains.

On a standard Linux Docker Engine installation, add the following settings to /etc/docker/daemon.json:

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

This configuration retains up to three log files of 10 MB each per container. When the limit is exceeded, Docker rotates the logs and removes the oldest file. Messages removed through rotation are no longer available through docker logs.

If daemon.json already contains other settings, merge these keys into the existing configuration rather than replacing the file. Values under log-opts must be strings, including "3".

Restart Docker Engine to apply the configuration. On production hosts, plan this carefully because restarting the daemon can interrupt running containers unless Docker’s live-restore feature is enabled and supported for the operation:

sudo systemctl restart docker

On Docker Desktop, edit the equivalent JSON configuration under Settings > Docker Engine and apply the changes there.

The new defaults apply only to newly created containers. Existing containers retain their original logging settings and must be recreated to use the new configuration.

You can also configure rotation for an individual container without changing the daemon’s defaults:

docker run -d --name my-app-rotated \
  --log-driver json-file \
  --log-opt max-size=10m \
  --log-opt max-file=3 \
  my-app:latest

Replace my-app:latest with your application image. The -d flag starts the container in detached mode, allowing it to run in the background. The explicit --log-driver json-file ensures the rotation settings apply even when the daemon uses another driver by default.

Use the local Logging Driver for Automatic Rotation

For standalone Docker hosts, the local logging driver provides automatic rotation and compression without requiring you to configure file limits.

By default, it retains up to five files of 20 MB each, or approximately 100 MB of log data per container before compression. Older files are removed as new ones rotate in, and docker logs continues to work normally.

To make local the default driver for newly created containers, set the following in your Docker daemon configuration:

{
  "log-driver": "local"
}

Apply the change using the same restart procedure described above, then recreate existing containers if they need the new driver.

The local driver is a practical choice when you want bounded on-host log storage without managing rotation settings for every container. If you need to retain logs beyond those limits or across container removal, collect them in a central logging backend.

How to Centralize Docker Container Logs

Local logs are useful for investigating individual containers, but they become harder to manage when an application spans multiple hosts or containers are frequently replaced. Log rotation also removes older messages, limiting how far back you can investigate. Centralized logging keeps logs accessible independently of container lifecycles and lets you search activity across services from one place.

You can forward logs directly using Docker’s remote logging drivers or use a host-level collector to gather them. The choice depends on your existing logging infrastructure and whether you want to configure forwarding for individual containers.

Forward Docker Logs with Logging Drivers

Docker’s remote logging drivers send container output to an external destination. Common options include:

  • fluentd: Sends structured container logs to Fluentd, which can forward them to a logging backend.
  • syslog: Forwards messages to a syslog receiver over UDP, TCP, or TLS.
  • gelf: Sends logs to a GELF-compatible receiver such as Graylog.
  • splunk: Sends logs directly to Splunk through its HTTP Event Collector.

For example, if you already have a Fluentd receiver listening on port 24224, you can configure a container to forward logs to it:

docker run -d --name my-app-forwarded \
  --log-driver fluentd \
  --log-opt fluentd-address=192.0.2.10:24224 \
  my-app:latest

Replace 192.0.2.10 with the address of your Fluentd receiver and my-app:latest with your application image. The receiver must be reachable from the Docker daemon. By default, the container fails to start if Docker cannot connect to Fluentd; fluentd-async allows an asynchronous connection instead.

You can apply the same driver and destination settings as daemon-wide defaults through daemon.json, using the configuration procedure covered earlier. Remember that changes to logging drivers apply only to newly created containers.

Remote forwarding also affects how failures are handled. Docker uses blocking log delivery by default, which can stall application output when the logging driver cannot keep up. You can set mode=non-blocking to buffer messages instead, but Docker drops new messages if the buffer fills. The default buffer size is 1m, so this trades the risk of blocking for potential log loss.

Docker also maintains a local dual-logging cache for remote drivers that cannot read logs back. This allows docker logs to continue retrieving recent output, even when the primary destination is remote. The cache rotates automatically, retaining up to five files of 20 MB each before compression by default.

The cache is not a delivery guarantee. Failed remote writes can also prevent cache entries from being recorded. If you disable the cache, docker logs may return a configured logging driver does not support reading error, leaving the remote backend as your source for those logs.

Collect and Investigate Docker Logs with groundcover

On standalone Linux hosts, groundcover provides another way to centralize Docker container logs. Its sensor collects logs natively from containers running on the machine, alongside application traces and host CPU, memory, and disk metrics. This lets you investigate container activity without configuring a remote logging driver for each application.

Install the sensor using the Linux host installation procedure. Installation requires a sensor ingestion key and environment configuration, and the sensor runs as a systemd service named groundcover-sensor. Check its status with:

systemctl status groundcover-sensor

Once logs are ingested, use Log Explorer to search across containers and narrow results by time, log level, workload, or parsed attributes. For structured JSON logs containing a request.path field, you can filter requests to /status using:

@request.path:"/status"

You can also use Log Patterns to group recurring messages and suppress repetitive entries such as health checks. This helps identify repeated failures without reading every log line individually.

When application logs include a recognized trace_id and the matching trace has been ingested, log-to-trace correlation lets you move from an error message to the request trace associated with it. This provides request-level context that searching container logs alone cannot.

For longer investigations, configure log retention under Settings > Storage Management > Logs. You can set a default retention period and apply different log retention policies to selected logs using index filters, keeping important history beyond Docker’s local rotation limits.

Troubleshooting Empty or Missing Docker Container Logs

An empty docker logs result does not always mean the application produced no messages. The application may be writing to files, buffering its output, or using a logging driver that does not expose logs locally. Missing older messages may also have been removed through rotation or container deletion. Start by checking whether the container still exists with docker ps -a, then use the symptoms below to narrow down the cause.

The Application Writes to Files or Buffers Its Output

docker logs captures output written to stdout and stderr, not arbitrary files inside a container. If your application writes exclusively to /var/log/..., those messages will not appear unless you redirect them to the container’s output streams.

For example, the official NGINX image uses symbolic links to send access and error logs to stdout and stderr:

RUN ln -sf /dev/stdout /var/log/nginx/access.log \
    && ln -sf /dev/stderr /var/log/nginx/error.log

You can use the same approach when building an image for an application that writes to fixed log-file paths, or configure the application to write directly to stdout and stderr.

If messages appear late or in bursts, check whether the application buffers its output. For example, Python buffers stdout when running without an interactive terminal. Run Python with -u to make its output unbuffered:

CMD ["python", "-u", "app.py"]

Alternatively, set the following in your Dockerfile:

ENV PYTHONUNBUFFERED=1

Either option makes Python’s stdout and stderr unbuffered, allowing messages to reach Docker without waiting for Python’s output buffer to flush.

The Logging Driver or Local Cache Prevents Log Access

If docker logs returns an error or shows less output than expected, check the container’s configured logging driver:

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

The result helps you identify the next step:

  • none: Docker does not collect logs for the container. Recreate it with a logging driver that captures output if you need to use docker logs.
  • Remote driver with local caching disabled: docker logs can return configured logging driver does not support reading. Check the remote logging backend for existing messages, or recreate the container with the local cache enabled if you need CLI access.
  • Remote driver with gaps in the logs: Failed remote writes or cache writes can leave missing entries. Check the destination’s connectivity and the Docker daemon logs for delivery errors. If non-blocking delivery is enabled, a full buffer can also cause messages to be dropped.
  • fluentd with an unavailable receiver: The container can fail to start when Fluentd is unreachable. Check the configured fluentd-address; use fluentd-async if asynchronous connection behavior is required.

If the container uses json-file, local, or journald, and the command succeeds but returns nothing, check whether the application wrote to stdout or stderr and whether your time filters exclude the messages. Try docker logs my-app without --since, --until, or --tail before investigating further.

The Container Was Removed or Older Logs Were Rotated

An exited container remains accessible through docker logs while it still exists and its logs are retained. Once you remove the container, Docker no longer has a container ID or name you can query for its logs.

This can happen with docker run --rm, which automatically removes the container when it exits. When debugging a short-lived process, omit --rm so you can inspect its output afterward.

Rotation can also explain why newer messages appear but older ones are missing. Once the configured retention limits are reached, Docker removes older log files, and docker logs cannot retrieve those discarded entries.

If the messages are no longer available locally, check your central logging backend, if one was collecting them at the time. For future investigations, configure retention and centralized collection before the history you need is deleted.

FAQs

docker logs displays the available stdout and stderr output captured from a container. docker inspect shows its configuration and metadata, including the logging driver and the .LogPath field. Use docker logs to read application messages and docker inspect to check how they’re stored. The log-file path may be empty for drivers that don’t use a directly exposed file.

Redirect both stdout and stderr to a file using your shell:

docker logs my-app > container.log 2>&1

Add -t to include timestamps or --since and --until to export a specific period. This saves the logs currently accessible through Docker, not messages already removed by rotation. Use centralized collection if you need ongoing retention.

No. Container logs contain application output, while Docker Engine logs record activity from the Docker daemon (dockerd). On Linux systems using systemd, inspect daemon logs with:

journalctl -u docker.service

These logs help diagnose Docker Engine failures and logging-driver errors rather than application-level problems. On Docker Desktop, daemon logs are stored separately; their locations depend on the operating system and are covered in the Docker daemon logging reference.

Sign up for Updates

Keep up with all things cloud-native observability.

We care about data. Check out our privacy policy.