How do I read recent Docker container logs without flooding the terminal?
docker logs reads output collected for the selected container’s standard output and standard error, subject to its logging driver. Limit both the time window and number of lines when investigating an incident. A container may also write separate application files that this command does not display.
Before you start
- Authorised Docker access and the exact container name.
Instructions
1. Confirm the container
Check its state and name before collecting logs. Similar application names can exist in development, staging and production contexts.
docker ps --all --filter name=appLists matching containers; confirm the exact name before using it below.
2. Read a bounded time window
Replace app with the actual container name. Keep the time window close to the incident and redact sensitive values before sharing any extract.
docker logs --since 15m --tail 100 --timestamps appReturns up to the most recent hundred collected lines from the selected fifteen-minute window.
3. Follow a brief reproduction if needed
Follow only while reproducing an approved request, then press Ctrl+C. This stops the log client, not the running application container.
docker logs --follow --since 2m --tail 20 appStreams new collected output after a small initial extract.
Check the result
- Relevant error entries align with the failing request time and the correct container instance.
Troubleshooting
- No application errors appear
- Check whether the application writes files or uses a remote logging driver, and whether the selected container was replaced after the incident.
- Logs contain secrets or customer details
- Share only a redacted minimal extract and correct the application’s logging practice through its owner.
Official references
Use the documentation for your installed version when a flag, service name or platform feature differs.
