{"id":"08bb95da4b54036a","repo":"docker/cli","slug":"content-size-not-available-for-stdin","errorCode":null,"errorMessage":"content size not available for stdin","messagePattern":"content size not available for stdin","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"cli/command/container/cp.go","lineNumber":412,"sourceCode":"\t\t// type of conflict (e.g., non-directory overwriting an existing directory\n\t\t// or vice versa) the extraction will fail. If the destination simply did\n\t\t// not exist, but the parent directory does, the extraction will still\n\t\t// succeed.\n\t\t_ = err // Intentionally ignore stat errors (see above)\n\t}\n\n\tvar (\n\t\tcontent         io.ReadCloser\n\t\tresolvedDstPath string\n\t\tcopiedSize      int64\n\t\tcontentSize     int64\n\t\tsizeErr         error\n\t)\n\n\tif srcPath == \"-\" {\n\t\tcontent = os.Stdin\n\t\tresolvedDstPath = dstInfo.Path\n\t\tsizeErr = errors.New(\"content size not available for stdin\")\n\t\tif !dstInfo.IsDir {\n\t\t\treturn fmt.Errorf(`destination \"%s:%s\" must be a directory`, copyConfig.container, dstPath)\n\t\t}\n\t} else {\n\t\t// Prepare source copy info.\n\t\tsrcInfo, err := archive.CopyInfoSourcePath(srcPath, copyConfig.followLink)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tcontentSize, sizeErr = localContentSize(srcInfo.Path)\n\n\t\tsrcArchive, err := archive.TarResource(srcInfo)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdefer srcArchive.Close()\n","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/container/cp.go#L394-L430","documentation":"In copyToContainer, when the source is `-` the CLI reads a tar archive from stdin and sets sizeErr to this error instead of a byte count, because a stream's total size cannot be known up front. It is a sentinel used to disable the copy progress display, not a fatal failure of the copy itself — though it surfaces where code paths need the content size.","triggerScenarios":"`docker cp - mycontainer:/dest/dir` (tar archive piped on stdin). localContentSize is never called; sizeErr is pre-set at cp.go:412 since os.Stdin has no determinable length.","commonSituations":"Piping tar streams into containers (`tar -cf - . | docker cp - ctr:/app`) and wondering why no progress/size is shown; tooling that parses cp output expecting a size.","solutions":["No fix needed for the copy itself — it proceeds; the size is simply unavailable for stdin, so progress reporting is skipped.","If you need size reporting, write the tar to a file first and copy the file/directory by path instead of streaming via `-`.","Ensure the stdin source is a valid tar archive and the destination is an existing directory (a non-directory destination fails separately)."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","docker-cp","stdin","streaming"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}