Software & Applications

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:

docker ps

(for running containers) or:

docker ps -a

(to include stopped containers).

2. View logs: Run the following command, replacing `` with the actual container ID or name:

docker logs

Useful Options
- Follow logs in real-time: Add the `-f` flag to stream logs as they are generated:

docker logs -f

- View recent logs: Use the `--tail` option to show only the last `n` lines:

docker logs --tail 100

- Include timestamps: Add the `-t` flag to show timestamps for each log entry:

docker logs -t

- Filter by time: View logs since a specific time or date:

docker logs --since "2025-07-14"

  or for the last 30 minutes:

docker logs --since 30m

Example
To view the logs of a container named `my-app` in real-time with timestamps:

docker logs -f -t my-app

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/