By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
This topic helps you manage Docker container logs. docker logs.
docker ps
docker ps -aq
docker logs -f <container_id>
docker logs -t <container_id>
docker logs -n 10 <container_id>
docker logs --since 2022-01-01 <container_id>
docker rm <container_id>
Purpose: Monitor container logs in real-time.Command: docker logs -f <container_id> Flags: -f flag to follow the logs.
Purpose: Get the last 10 lines of container logs.Command: docker logs -n 10 <container_id> Flags: -n flag to get the last 10 lines.
Purpose: Get logs since a specific timestamp.Command: docker logs --since 2022-01-01 <container_id> Flags: --since flag to get logs since a specific timestamp.
Error message: "Error: No such container: " Why it happens: Container does not exist.Fix: docker ps to check if the container is running.
Error message: "Usage: docker logs [OPTIONS] CONTAINER" Why it happens: Incorrect flag used.Fix: Check the correct flags for the docker logs command.
Error message: "Error: Permission denied" Why it happens: Insufficient permissions.Fix: Run the command with sudo or use a user with sufficient permissions.
Situation: Container is running.Command to run: docker logs -f <container_id> Correct response: Logs are displayed in real-time.
Situation: Container is not running.Command to run: docker logs -f <container_id> Correct response: Error message "Error: No such container: ".
Situation: Incorrect flag used.Command to run: docker logs -f <container_id> --invalid-flag Correct response: Error message "Usage: docker logs [OPTIONS] CONTAINER".
docker logs -f <container_id> --invalid-flag
• docker logs command can be used with multiple containers.• -f flag to follow logs.• -t flag to include timestamps.• -n flag to get the last n lines.• --since flag to get logs since a specific timestamp.• ⚠️ -f flag will continue to run until manually stopped.• ⚠️ --since flag requires a timestamp in the format "YYYY-MM-DD HH:MM:SS".• ⚠️ docker logs command will display logs from the last 10 lines by default.• ⚠️ docker logs command will display logs from the last 10 minutes by default.• ? Verify with 'docker version' for any changes in the command.
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.