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.
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 logs2. 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 error5. 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.txtSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
