I'm trying to retrieve container logs using Docker API.
Open API documentation of Docker states to get the container logs; syntax that should be used is;
/containers/{id}/logs
According to documentation there could be three response statuses; 200, 404 and 500.
You can see the part of the documentation below;
responses:
200:
description: |
logs returned as a stream in response body.
For the stream format, [see the documentation for the attach endpoint](#operation/ContainerAttach).
Note that unlike the attach endpoint, the logs endpoint does not upgrade the connection and does not
set Content-Type.
schema:
type: "string"
format: "binary"
404:
description: "no such container"
schema:
$ref: "#/definitions/ErrorResponse"
examples:
application/json:
message: "No such container: c2ada9df5af8"
500:
description: "server error"
schema:
$ref: "#/definitions/ErrorResponse"
The interesting part for me is when I make a call I get 400 error which doesn't exist in the docs. Response message is like;
{
"message": "Bad parameters: you must choose at least one stream"
}
How can I get the container logs using Docker API ?
Specify where to return logs from by sending the stdout
or stderr
query parameters. Example:
curl --unix-socket /var/run/docker.sock http://localhost/containers/containerId/logs?stdout=true