
The docker logs command is a key diagnostic tool that outputs everything a container writes to standard output (stdout) and standard error (stderr). Whether you're troubleshooting failed startups, inspecting runtime behavior, or reviewing error traces, this command offers a direct view into container activity without needing to attach or exec into it.
While docker logs is ideal for capturing application output, it works best alongside tools like docker inspect and docker exec, which provide metadata and interactive shell access, respectively. This article explains how to use docker logs to inspect, stream, and filter logs so you can pinpoint and resolve issues efficiently.
If you're already familiar with Docker and need a quick reference for checking container logs, use the commands below:
These commands cover the most common use cases for viewing and filtering logs. Continue reading for in-depth explanations and usage examples.
Use the docker logs command to view output from a container’s standard output (stdout) and standard error (stderr). This includes application logs, startup messages, and error details, essential for diagnosing issues.
docker logs: Displays the container's complete stdout and stderr output.<container_id>: The container’s short or full ID. Run docker container ls to find it.List the currently running containers.
Output.
View the container logs using its ID or name.
Output.
To monitor a running container continuously, use the -f or --follow flag with the docker logs command. This streams log output in real time and is useful when debugging live services or checking active processes.
docker logs: Outputs all logs from the container's stdout and stderr.-f or --follow: Continuously streams new log entries as they appear.<container_id>: The container’s short or full ID.Use this flag when observing a container's real-time performance or verifying live system responses.
List running containers.
Stream logs from a selected container.
This streams logs from the container in real time. Replace 8f8f72f26159 with your container ID. To stop, press Ctrl + C.
Docker allows you to filter container logs using specific flags. These filters help reduce log clutter, narrow down events within a time window, or extract only the most relevant entries during debugging.
The following flags control how much log data is shown and how it's displayed:
Each of these flags can be combined with docker logs to help you pinpoint issues more efficiently. The following sections explain their syntax and use cases with examples.
docker logs: Displays logs from the container’s stdout and stderr.--tail <number_of_lines>: Limits output to the last n lines. Accepts values like 10, 100, or 500.<container_id>: The container’s short or full ID (use docker container ls to find it).List running containers to find the container ID.
View the last 10 lines of logs from the container.
Output.
docker logs: Displays logs from the container’s stdout and stderr.--since="<timestamp>": Filters log entries from the specified time onward. Accepts absolute timestamps like 2025-05-20T10:00:00 or relative formats like 30m, 2h, or 1d.<container_id>: The container’s short or full ID.Use this flag when you're troubleshooting specific time-based events or testing application behavior within a known timeframe.
List running containers.
View logs generated after a specific timestamp.
This command displays logs from container ea45fa0f96ac starting at the given date and time.
View logs from the last 30 minutes.
This filters output to just the most recent 30 minutes of activity.
docker logs: Displays logs captured from the container's stdout and stderr.--until="<timestamp>": Filters logs to show entries created before a specified time. Accepts absolute timestamps like 2025-05-20T12:00:00 or relative values like 30m or 2h.<container_id>: The container’s short or full ID.--since to define a custom time window.Use this flag to isolate logs that occurred before an application error, crash, or deployment.
List running containers.
Identify the container ID you want to inspect.
To view logs created before a specific time (e.g., May 28, 2025, at 8:44:39 p.m.).
Output.
To show logs generated more than two hours ago.
This flag is especially useful when reviewing logs leading up to a failure window or diagnosing events that happened earlier in the day.
docker logs: Displays logs from the container's stdout and stderr.--timestamps: Adds a timestamp to the beginning of each log line.<container_id>: The container’s short or full ID.Use this flag to track when log entries occur, especially during performance bottlenecks or request timing analysis.
Identify the container to inspect.
Display logs with timestamps.
Output.
This flag is especially helpful when working with log aggregators or correlating logs across services.
Running docker logs can sometimes result in errors such as:
or
These usually occur due to referencing the wrong container or lacking proper permissions. Use the following solutions to resolve these issues.
This error appears if the container ID or name is incorrect, incomplete, or the container has already stopped.
List running containers.
If the container isn’t running, include stopped containers.
Use the correct container name or full ID.
This typically happens when the current user does not have access to the Docker daemon.
Use sudo to run the command.
To avoid using sudo each time, add your user to the docker group.
Then log out and back in for the group change to take effect.
This article showed you how to use the docker logs command to debug containers effectively. You learned how to view logs from a running container, stream real-time output, and filter log data using flags like --tail, --since, --until, and --timestamps. You also reviewed how to fix common errors related to invalid container IDs or permission issues. These techniques help you diagnose problems faster and maintain stable Docker environments. For more details, see the official Docker logs documentation.
0 Comments
Be the first to comment and share your perspective with the community.