Skip to content
Software capabilities

Docker capability

Read Docker container logs

Use docker logs for a quick check of container output. Call the Engine API or Docker SDK when a program needs to fetch the same log stream.

Documentation reviewed

Ways to do it

CLI

docker container logs <container>

Print a container’s captured output. Use --tail for recent lines and --follow to keep reading new output.

Requirements
Docker CLI connected to the right daemon, with access to the container name or ID.
Limitations
It reads captured standard output and error. Logs written only to files inside the container may be absent.

Example

docker container logs --tail 50 "$CONTAINER"
Read source: Docker CLI container logs

API

GET /containers/{id}/logs

Request standard output, standard error, or both from the Docker Engine API.

Requirements
Access to the Docker daemon and the container’s ID or name. Set stdout and stderr query parameters for the streams you need.
Limitations
The Engine API documents support for the json-file and journald logging drivers for this endpoint.

Example

GET /v1.52/containers/CONTAINER_ID/logs?stdout=true&stderr=true&tail=50
Read source: Docker Engine API ContainerLogs

SDK

Container.logs()

Read a container’s captured output from Python. Pass tail to bound the result, or stream=True when you need incremental reads.

Requirements
A Docker SDK client with access to the daemon that owns the container.
Limitations
Without streaming, the returned data is bytes. Decode it before passing it to a text consumer.
Read source: Docker SDK for Python container logs