engine-api icon indicating copy to clipboard operation
engine-api copied to clipboard

ContainerLogs with default ContainerLogsOption

Open htfy96 opened this issue 9 years ago • 1 comments

I copied

func ExampleClient_ContainerLogs_withTimeout() {
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()

    client, _ := NewEnvClient()
    reader, err := client.ContainerLogs(ctx, "container_id", types.ContainerLogsOptions{})
    if err != nil {
        log.Fatal(err)
    }

    _, err = io.Copy(os.Stdout, reader)
    if err != nil && err != io.EOF {
        log.Fatal(err)
    }
}

from the example at container_logs_test.go, but the server raised an error Error response from daemon: Bad parameters: you must choose at least one stream.

Then I changed types.ContainerLogsOptions{} with types.ContainerLogsOptions{ShowStdout: true} and everything worked well.

So I was wondering whether this example could be misleading for beginners, or is there anything that I didn't notice?

htfy96 avatar Aug 01 '16 09:08 htfy96

as the error said, you have to choose one stream either stdout or stderr. If you don't input any of these option to be true, it would panic.

zsluedem avatar Feb 23 '18 03:02 zsluedem