Cloud Native 3 min read

Master Docker Log Commands: Quick Tips for Efficient Debugging

This guide presents essential Docker log techniques—including displaying all logs, real‑time streaming, tailing, time‑based filtering, combining options, and redirecting output to files—to help developers quickly troubleshoot containerized applications.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Master Docker Log Commands: Quick Tips for Efficient Debugging

When developing Docker‑based applications, effective log handling can greatly improve debugging efficiency. Below are common log operation techniques.

1. Show all logs

# Show all logs of a container
$ docker logs [OPTIONS] <CONTAINER>
# Show logs of all containers started with docker‑compose
$ docker-compose logs

2. Show real‑time logs

Similar to Linux tail -f filename, it streams the latest output to the screen.

$ docker logs -f <CONTAINER>

3. View log tail

Equivalent to tail -n 20 filename, displays the last 20 lines.

$ docker logs --tail 20 <CONTAINER>

4. Filter logs with grep

Example: find all logs containing “error”.

$ docker logs | grep error

5. View logs by time

Use --since to show logs after a specific timestamp, and --until for an end time.

$ docker logs --since 2018-09-25T12:01:46.452616Z <CONTAINER>
$ docker logs --since 2018-09-25T12:01:48.551341Z --until 2018-09-25T12:01:48.561714Z <CONTAINER>

6. Combine options

Options can be combined, e.g. tail the last 10 lines and filter for “info”.

$ docker logs --tail 10 <CONTAINER> | grep info
$ docker logs -f --since xxx --tail=10 <CONTAINER>

7. Write logs to a file

Redirect error logs to a file, or script the output for further processing.

$ docker logs -t <CONTAINER> | grep error >> logs_error.txt
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CLIContainertroubleshootinglogs
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.