You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker API v1.40获取容器日志遇400错误:如何正确调用接口?

Fixing the "Bad parameters: you must choose at least one stream" Error in Docker API Logs Request

Hey there! That 400 error you're hitting is a common gotcha with the Docker logs API—while the docs list the main status codes, they don't explicitly highlight this required parameter check. Let's break down how to fix it and properly fetch container logs.

Why You're Getting the 400 Error

The /containers/{id}/logs endpoint requires you to specify at least one log stream you want to retrieve: either the container's standard output (stdout) or standard error (stderr). If you skip both parameters, Docker has no idea which logs to send back, hence the "Bad parameters" message.

Correct Request Format

To make a valid request, add either stdout=true or stderr=true (or both) as query parameters. Here's a breakdown of key parameters you'll use:

  • stdout=true: Fetch logs from the container's standard output stream
  • stderr=true: Fetch logs from the container's standard error stream
  • Optional extras:
    • follow=true: Keep the connection open to stream new logs in real-time
    • tail=N: Only retrieve the last N lines of logs (replace N with a number, or use all for all logs)
    • timestamps=true: Include timestamps with each log line

Example Requests

Basic Request (Fetch Both stdout and stderr)

Using curl to get the last 20 lines of both streams:

curl -X GET "http://localhost:2375/containers/your-container-id/logs?stdout=true&stderr=true&tail=20"

Real-Time Log Streaming

To follow logs as they're generated:

curl -X GET "http://localhost:2375/containers/your-container-id/logs?stdout=true&stderr=true&follow=true&timestamps=true"

Additional Notes

  • Make sure your Docker daemon is configured to allow API access (by default, it listens on unix:///var/run/docker.sock; if using TCP, ensure it's enabled securely)
  • If you get a 404 error, double-check that the container ID is correct and the container exists
  • For authenticated API access, include your auth token in the request headers (e.g., Authorization: Bearer your-token)

内容的提问来源于stack exchange,提问作者Capan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:55:51