Follow logs

3 snippets across 2 stacks - Docker, Bash & Linux

Also written as follow log

DKDocker

View Container Logs

DK · Containers
Syntax
docker logs [options] <container>
Example
docker logs web-api
docker logs -f --tail 50 web-api
docker logs --since 10m web-api
Output
Server listening on port 3000
GET /api/users 200 12ms

Note Use -f to follow in real time (like tail -f). Combine --tail and --since to avoid dumping thousands of lines. Logs persist until the container is removed.

Follow Logs in Real Time

DK · Debugging
Syntax
docker logs -f [--tail <n>] <container>
Example
docker logs -f --tail 100 web-api
docker logs -f --since 5m web-api
Output
Server started on port 3000
GET /api/health 200 2ms
POST /api/users 201 45ms

Note Combine --tail to avoid the initial flood and --since to only see recent entries. Pressing Ctrl+C stops following but does not affect the container.

SHBash & Linux

View End of File / Follow Logs

SH · File Content
Syntax
tail [options] file
Example
tail -n 50 error.log
tail -f /var/log/nginx/access.log
tail -f app.log | grep --line-buffered 'ERROR'

Note -f follows the file in real-time as new lines are appended, which is indispensable for monitoring logs. Use Ctrl+C to stop following. -F will keep retrying if the file is rotated or recreated.

Frequently asked questions

How does Docker handle follow logs?
This task is covered in 2 stacks on this page: Docker, Bash & Linux. The "View Container Logs" snippet in Docker uses `docker logs [options] <container>`.
Which command does the Docker example use?
The "View Container Logs" snippet uses `docker logs [options] <container>`, from the Containers section of the Docker cheat sheet.
Which stacks cover "follow logs" on this page?
Docker, Bash & Linux. Together they hold 3 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "View Container Logs": Use -f to follow in real time (like tail -f). Combine --tail and --since to avoid dumping thousands of lines. Logs persist until the container is removed.