> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Docker Question 1

> Learn to view and filter Docker container logs to display the last 200 lines for effective debugging and maintenance.

In this article, you'll learn how to view logs from a Docker container and filter the output to display only the last 200 lines. This technique is essential for debugging, routine maintenance, or preparing for DevOps and containerization interviews.

When working with Docker on a daily basis, getting accustomed to frequently used commands is crucial. One of the most common tasks is checking container logs. While the base command is straightforward, you can fine-tune it with additional arguments to display only a specific portion of the output—like the last 200 lines. This approach eliminates the need to scroll through a large number of log entries unnecessarily.

<Callout icon="lightbulb" color="#1CB2FE">
  Using the `--tail` flag is very effective in focusing on recent events in the container log, which can be particularly useful when troubleshooting issues.
</Callout>

## Viewing Container Logs

To display the logs of a specific container, use the following command:

```bash theme={null}
docker container logs <container_name>
```

Replace `<container_name>` with the appropriate name or identifier of your container. For example, if you're investigating the logs for a container named "webapp," substitute it accordingly.

## Filtering Logs to the Last 200 Lines

To refine your log output and display just the last 200 lines, append the `--tail` flag as shown below:

```bash theme={null}
docker container logs --tail 200 <container_name>
```

This modified command ensures that you only see the most recent portion of the logs, which streamlines troubleshooting and debugging processes.

## Useful Links and References

* [Docker Documentation](https://docs.docker.com/)
* [Docker CLI Reference](https://docs.docker.com/engine/reference/commandline/cli/)

By mastering these commands, you can efficiently navigate Docker logs in both routine and high-pressure troubleshooting scenarios.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/devops-interview-preparation-course/module/955d2fcf-4c92-4480-b86e-081d67d83e88/lesson/0a74b90c-33d9-4499-ac9b-ae4acbcf2a34" />
</CardGroup>
