Docker
Beginner
1 min read
Container Logs and Debugging
Example
# Tail logs of a named container
docker logs api --tail 50 --follow
# Filter logs by time
docker logs api --since 1h
docker logs api --since "2025-01-15T10:00:00"
# Open a shell in a running container
docker exec -it api sh
docker exec -it api bash
# Run a single command inside the container
docker exec api env
docker exec api cat /etc/hosts
docker exec api ps aux
# Check container resource usage
docker stats api --no-stream
# Inspect network and mounts
docker inspect api \
--format '{{range .Mounts}}{{.Source}} -> {{.Destination}}{{"\n"}}{{end}}'
# Stream Docker daemon events
docker events --filter container=api
# Debug a crashed container by overriding entrypoint
docker run --rm -it --entrypoint sh myapp:2.1.0
Related Resources
Docker Reference
Complete tag & property list
Docker How-To Guides
Step-by-step practical guides
Docker Exercises
Practice what you've learned
More in Docker