Docker API v1.40 获取容器日志

Docker API v1.40 getting container logs

我正在尝试使用 Docker API 检索容器日志。

打开 API 状态的 Docker 文档以获取容器日志;应该使用的语法是;

/containers/{id}/logs

根据文档,可能有三种响应状态; 200404500.

您可以看到下面的部分文档;

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 获取容器日志?

通过发送 stdoutstderr 查询参数指定 return 日志的来源。示例:

curl --unix-socket /var/run/docker.sock http://localhost/containers/containerId/logs?stdout=true