Kritim Yantra
Apr 25, 2025
When working with Docker, one of the most important tasks during development or troubleshooting is viewing logs.
Whether you're debugging an error or just monitoring your application, the docker logs
command is your best friend.
In this post, you'll learn:
docker logs
command Letβs get logging! π
Docker logs are output streams (stdout and stderr) from containers. Anything your application prints (like console.log
, print()
, or error messages) will show up in the logs.
By default, Docker captures these logs and stores them using a logging driver (like json-file
).
docker logs [OPTIONS] CONTAINER
Replace CONTAINER
with the container name or ID.
Example:
docker logs my-container
docker logs
OptionsHere are the most useful flags you can use with the docker logs
command:
Option | Description |
---|---|
-f or --follow |
Stream logs in real-time (like tail -f ) |
--since |
Show logs since a given time (e.g., --since="10m" ) |
--tail |
Show only the last N lines (e.g., --tail 100 ) |
-t or --timestamps |
Include timestamps with each log line |
--until |
Show logs up until a certain time |
docker logs my-container
docker logs -f my-container
This is useful when you're running an app and want to watch the output live (like a web server).
docker logs --since 15m my-container
Or a specific time:
docker logs --since="2024-04-25T10:00:00" my-container
docker logs --tail 100 my-container
docker logs -t my-container
docker logs -f --since 10m --tail 50 -t my-container
This shows the last 50 lines of logs from the last 10 minutes, with timestamps, and keeps streaming new lines as they come in.
Use the following command to list running containers:
docker ps
This will show something like:
CONTAINER ID IMAGE COMMAND STATUS NAMES
123abc456def myapp:latest "npm start" Up 5 mins my-container
Now you can use docker logs my-container
or docker logs 123abc456def
.
By default, logs are stored in:
/var/lib/docker/containers/<container-id>/<container-id>-json.log
π Tip: You usually don't need to access this file directly unless youβre doing advanced debugging.
Docker supports multiple logging drivers, like:
json-file
(default)syslog
journald
awslogs
gelf
fluentd
logstash
To check which logging driver is being used:
docker inspect my-container --format='{{.HostConfig.LogConfig.Type}}'
-f
while debugging to watch logs in real-time.If logs are getting too large, you can use log rotation in your docker-compose.yml
or Docker run command:
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
This keeps 3 files of 10 MB each β automatically rotating when theyβre full.
Hereβs a quick recap:
Task | Command |
---|---|
View logs | docker logs container |
Stream logs | docker logs -f container |
Last N lines | docker logs --tail N container |
Logs since | docker logs --since 10m container |
Logs with time | docker logs -t container |
Understanding Docker logs is essential for debugging and monitoring your apps. Whether you're building, testing, or running in production, mastering the docker logs
command gives you better visibility into your containers.
Now go ahead and try it out in your terminal β and may your logs be ever helpful! π³π
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google