我正在尝试使用Docker API检索容器日志。
打开Docker状态的API文档以获取容器日志;应该使用的语法是;
/ containers / {id} / logs
根据文档,可能存在三种响应状态; 200 , 404 和 500 。
您可以在下面查看文档的一部分;
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"
对我来说有趣的部分是,当我打电话时,我收到400错误,而该错误在文档中不存在。 响应消息就像;
{
"message": "Bad parameters: you must choose at least one stream"
}
如何使用Docker API获取容器日志?
答案 0 :(得分:0)
通过发送stdout
或stderr
查询参数来指定从何处返回日志。示例:
curl --unix-socket /var/run/docker.sock http://localhost/containers/containerId/logs?stdout=true