{"record":{"id":"0d1d10a006c48c4c","repo":"docker/cli","slug":"tty-service-logs-only-supported-with-raw","errorCode":null,"errorMessage":"tty service logs only supported with --raw","messagePattern":"tty service logs only supported with --raw","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/service/logs.go","lineNumber":106,"sourceCode":"\t\tres, err := apiClient.TaskInspect(ctx, opts.target, client.TaskInspectOptions{})\n\t\tif err != nil {\n\t\t\tif errdefs.IsNotFound(err) {\n\t\t\t\t// if the task isn't found, rewrite the error to be clear\n\t\t\t\t// that we looked for services AND tasks and found none\n\t\t\t\terr = fmt.Errorf(\"no such task or service: %v\", opts.target)\n\t\t\t}\n\t\t\treturn err\n\t\t}\n\n\t\ttty = res.Task.Spec.ContainerSpec.TTY\n\t\tmaxLength = getMaxLength(res.Task.Slot)\n\n\t\t// we can't prettify tty logs. tell the user that this is the case.\n\t\t// this is why we assign the logs function to a variable and delay calling\n\t\t// it. we want to check this before we make the call and checking twice in\n\t\t// each branch is even sloppier than this CLI disaster already is\n\t\tif tty && !opts.raw {\n\t\t\treturn errors.New(\"tty service logs only supported with --raw\")\n\t\t}\n\n\t\t// now get the logs\n\t\tresponseBody, err = apiClient.TaskLogs(ctx, opts.target, client.TaskLogsOptions{\n\t\t\tShowStdout: true,\n\t\t\tShowStderr: true,\n\t\t\tSince:      opts.since,\n\t\t\tTimestamps: opts.timestamps,\n\t\t\tFollow:     opts.follow,\n\t\t\tTail:       opts.tail,\n\t\t\t// get the details if we request it OR if we're not doing raw mode\n\t\t\t// (we need them for the context to pretty print)\n\t\t\tDetails: opts.details || !opts.raw,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdefer responseBody.Close()","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/service/logs.go#L88-L124","documentation":"When `docker service logs` targets a TASK (not a service — the service lookup failed with NotFound at line 85, then the task was found at line 88), and that task's container spec has `TTY: true` (line 98), the CLI cannot apply its pretty-printing pipeline (task name resolution, slot padding, detail parsing via stdcopy). TTY container output is raw terminal data that is not multiplexed into stdout/stderr streams. This error fires at logs.go:105-106 when `tty && !opts.raw`, instructing the user to pass `--raw`.","triggerScenarios":"Running `docker service logs <task-id>` where the underlying service/task was created with `--tty` (allocating a pseudo-TTY), without passing `--raw`. The code path is: ServiceInspect returns NotFound → TaskInspect succeeds → TTY check fails.","commonSituations":"A service was created with `--tty` (common for interactive workloads), and an operator runs `docker service logs <task>` expecting formatted output. The pretty-printer cannot parse raw TTY byte streams.","solutions":["Add the `--raw` flag: `docker service logs --raw <task-id>`","Recreate the service without `--tty` if you need pretty-printed, multiplexed logs","Pipe the raw output through your own formatter if custom formatting is needed"],"exampleFix":"# before\ndocker service logs abc123def456\n# error: tty service logs only supported with --raw\n\n# after\ndocker service logs --raw abc123def456","handlingStrategy":"validation","validationCode":"// Before fetching task logs, check TTY status\nfunc shouldUseRawForTask(ctx context.Context, c client.APIClient, taskID string) (bool, error) {\n    res, err := c.TaskInspect(ctx, taskID, client.TaskInspectOptions{})\n    if err != nil {\n        return false, err\n    }\n    return res.Task.Spec.ContainerSpec.TTY, nil\n}\n// If TTY is true, always pass --raw (opts.raw = true)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --raw when fetching logs for services/tasks created with --tty","Document which services use TTY so operators know to add --raw for logs","Avoid using --tty for services where you need structured, pretty-printed logs"],"tags":["docker","cli","service","logs","tty"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}