Monitoring Docker containers is essential for keeping your applications stable and running smoothly. Docker logs let you see what’s happening inside your containers, and allows you to track performance, identify errors, and troubleshoot issues faster. In this guide, we’ll explain how to get Docker logs, understand them, and use that information to efficiently fix common container problems.
Table of Contents
- What Are Docker Logs
- How to Get/View Docker Logs
- Common Docker Logs Options and Flags
- Save Docker Logs to a File
- View Logs in Docker Compose
- Tips to Manage Docker Logs
What Are Docker Logs
Docker l…
Monitoring Docker containers is essential for keeping your applications stable and running smoothly. Docker logs let you see what’s happening inside your containers, and allows you to track performance, identify errors, and troubleshoot issues faster. In this guide, we’ll explain how to get Docker logs, understand them, and use that information to efficiently fix common container problems.
Table of Contents
- What Are Docker Logs
- How to Get/View Docker Logs
- Common Docker Logs Options and Flags
- Save Docker Logs to a File
- View Logs in Docker Compose
- Tips to Manage Docker Logs
What Are Docker Logs
Docker logs are the records of everything that happens inside a running Docker container. They include both standard output (stdout) and error messages (stderr), and allow you to find out how your container is performing and if there are any issues.
By default, Docker saves these logs as JSON files on the host system in the “/var/lib/docker/containers” directory. Each container has its own log file named “[container_id]-json.log”. You can open these files directly or use the docker logs command to view them in the terminal.
These logs contain application messages, warnings, and errors that help you debug problems. They may also include system information such as startup events or resource usage details.
To manage logs efficiently, Docker uses logging drivers. A logging driver defines where and how the logs are stored or sent. The default driver, json-file, saves logs locally in JSON format, but you can choose other drivers to send logs to external systems for easier management and analysis.
How to Get/View Docker Logs
The docker logs command lets you view logs from a running container that uses the “json-file” or journald logging driver. You can run it as follows:
docker logs [OPTIONS] CONTAINER_NAME_OR_ID
Replace CONTAINER_NAME_OR_ID with the actual name or ID of the container you want to check. To see the list of running containers, use this command:
docker ps
This command shows a list of active containers along with their IDs, names, status, and other useful information.

In the example above, Docker is running two containers: openwebui and ollama. To view the logs for a specific container, just use its name. For example, to check the logs of the openwebui container, run this command.
docker logs openwebui

You can also use the container ID instead of its name to view the logs. For example:
docker logs 1f351684ae30

Common Docker Logs Options and Flags
Docker lets you use different options with the docker logs command to control how the logs are displayed. Here are some useful ones.
| Option | Description | Example Command |
|---|---|---|
| –details | Shows extra information in the logs. | docker logs –details container_name |
| –follow, -f | Keeps showing new log entries in real time. | docker logs -f container_name |
| –since | Displays logs generated after a specific time or duration (for example, 2024-07-08T13:42:13Z or 10m). | docker logs –since 10m container_name |
| –tail, -n | Shows only a set number of lines from the end of the logs. | docker logs –tail 50 container_name |
| –timestamps, -t | Adds timestamps to each log line. | docker logs -t container_name |
| –until | Shows logs generated before a specific time. | docker logs –until 2024-07-08T14:00:00Z container_name |
For example, to see the latest 50 log entries of a specific container, run the docker logs command with the --tail option.
docker logs --tail 50 openwebui

Similarly, you can use other options, such as --follow to watch logs live or --since to filter logs by time according to your needs.
Save Docker Logs to a File
You can save Docker logs to a file using the simple redirection operator or built-in command options. For example, the following command saves the Docker logs to a file named “container_logs.txt”.
docker logs container_name > container_logs.txt

You can later open this file with any text editor (like Notepad, VS Code, or nano) to view the saved logs.

View Logs in Docker Compose
You can easily view logs from containers managed by Docker Compose using the docker compose logs command. For example, to see logs for all containers in your Compose project, run the following command:
docker compose logs
However, if you only want logs from one service, mention its name after the command.
docker compose logs service_name
Note: If you’re using an older version of Docker, the command might be docker-compose logs (with a hyphen). Both work similarly, depending on your Docker version.
Tips to Manage Docker Logs
Docker uses logging drivers to capture and store container output. By default, it uses the “json-file” driver, which saves logs in JSON format on the host system. You can switch to other drivers to send logs to external services or use a custom driver if you need more control.
Docker supports two log delivery modes. The blocking mode sends logs immediately but can slightly affect performance. The non-blocking mode stores logs temporarily in memory before sending them. It reduces delays but may lose logs if the memory buffer fills up.
You can also handle logging within your application for more flexibility. However, since container data is temporary, it is better to store logs in persistent storage or forward them to an external log management service.
Using Docker volumes is a reliable way to keep your logs safe. Volumes store data on the host machine and remain available even if a container stops or restarts. They are more suitable for long-term storage than bind mounts.
Another good approach is to use a dedicated logging container. It collects and manages logs from multiple containers and forwards them to a centralized system. This setup helps keep your main application containers lightweight and easy to manage.
Wrapping Up
Docker logs are essential for monitoring container performance and resolving issues quickly. You can use commands like docker logs and follow best practices, such as persistent storage and proper logging drivers, to ensure reliable log management. With an organized logging setup, you can keep your containers stable and your applications running smoothly. For better log monitoring and analysis, consider using tools such as the ELK Stack, Fluentd, Prometheus, and Grafana.