Docker logs command
docker logsThe command is used to retrieve and view container log output.
docker logsThis command is very useful, helping users debug and monitor running containers.
Syntax
docker logs [OPTIONS] CONTAINER
Common options:
-f, --follow: Follow log output (similar totail -f)。--since: Display logs starting from a specified time.-t, --timestamps: Display log timestamps.--tail: Display only the last part of the logs, for example--tail 10Display the last 10 lines.--details: Display extra detailed information provided to the logs.--until: Display logs up to a specified time.
Example
Display container logs
docker logs my_container
Display all logs of the container named my_container, with the output:
hello world hello world hello world ...
Follow log output
docker logs -f my_container
Continuously display the log output of my_container, with the output:
hello world hello world hello world ...
Display logs with timestamps
docker logs -t my_container
Display logs with timestamps, with the output:
2023-07-22T15:04:05.123456789Z hello world 2023-07-22T15:04:06.123456789Z hello world 2023-07-22T15:04:07.123456789Z hello world ...
Display logs starting from a specified time
docker logs --since="2023-07-22T15:00:00" my_container
Display logs after 2023-07-22T15:00:00.
Display the last 10 lines of logs
docker logs --tail 10 my_container
Display the last 10 lines of logs for my_container.
Display logs with extra detailed information
docker logs --details my_container
Display the logs of my_container, including extra detailed information.
Display logs up to a specified time
docker logs --until="2023-07-22T16:00:00" my_container
Display logs before 2023-07-22T16:00:00.
other extensions