- 103 Views
- 14/07/2025
How to view the logs of a Docker container on a Linux system
When working with Docker containers, logs are essential for debugging, monitoring, and understanding how your application is running. Docker provides a simple way to view container logs with the docker logs command
To view the logs of a Docker container, use the `docker logs` command. Here’s how:
1. Identify the container: Find the container ID or name using:
(for running containers) or:
(to include stopped containers).
2. View logs: Run the following command, replacing `` with the actual container ID or name:
Useful Options
- Follow logs in real-time: Add the `-f` flag to stream logs as they are generated:
- View recent logs: Use the `--tail` option to show only the last `n` lines:
- Include timestamps: Add the `-t` flag to show timestamps for each log entry:
- Filter by time: View logs since a specific time or date:
or for the last 30 minutes:
Example
To view the logs of a container named `my-app` in real-time with timestamps:
Notes
- Logs are fetched from the container’s stdout and stderr.
- If the container is stopped, you can still view its logs unless it was removed.
- For more details, check the Docker documentation: https://docs.docker.com/reference/cli/docker/container/logs/
