docker/cli · error
error while Copy ( )
Error message
error while Copy (%s): %w
What it means
Wrapped I/O error from io.Copy while shuttling bytes between stdio and the daemon raw stream connection in 'docker system dial-stdio'. The debugDescription distinguishes the 'stdin to stream' vs 'stream to stdout' direction.
Solutions
- Re-establish the operation once the daemon is stable ('docker version').
- Ensure the downstream consumer of stdout is alive for the whole transfer.
- For tcp endpoints, confirm network stability / reduce MTU issues.
Example fix
// before: copy fails mid-transfer due to daemon reset docker system dial-stdio // after: stabilize daemon then retry systemctl restart docker sleep 2 docker version && docker system dial-stdio
Defensive patterns
Strategy: try-catch
Type guard
func isCopyErr(err error) bool {
return err != nil && strings.Contains(err.Error(), "error while Copy")
} Try / catch
if _, err := io.Copy(to, from); err != nil {
if errors.Is(err, io.EOF) || isClosedConn(err) {
// peer closed cleanly
return nil
}
return fmt.Errorf("error while Copy (%s): %w", dir, err)
} Prevention
- Treat clean peer-close as EOF, not error, where appropriate.
- Keep the daemon stable across the proxied operation.
- Ensure the stdout consumer stays alive for the full transfer.
When it happens
Trigger: Either half of the bidirectional copy fails: the daemon closes the stream mid-transfer, the peer resets the connection, stdin/stdout hits an error, or the underlying connection breaks. Returned by copier at dial_stdio.go:84-86.
Common situations: Daemon restart during a proxied operation; peer disconnect; broken pipe on stdout (e.g. piping to a closed process); network interruption over a tcp daemon endpoint.
Related errors
- failed to open the raw stream connection
- conflicting options: cannot attach both user-defined and…
- conflicting options: cannot specify both --network-alias…
- conflicting options: cannot specify both --link and…
- conflicting options: cannot specify both --ip and…
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/1343fbce53aecbc5.
Report an issue: GitHub.
Appendix: source
Thrown at cli/command/system/dial_stdio.go:85
err = <-conn2stdout
case err = <-conn2stdout:
// return immediately without waiting for stdin to be closed.
// (stdin is never closed when tty)
}
return err
}
func copier(to halfWriteCloser, from halfReadCloser, debugDescription string) error {
defer func() {
if err := from.CloseRead(); err != nil {
logrus.Errorf("error while CloseRead (%s): %v", debugDescription, err)
}
if err := to.CloseWrite(); err != nil {
logrus.Errorf("error while CloseWrite (%s): %v", debugDescription, err)
}
}()
if _, err := io.Copy(to, from); err != nil {
return fmt.Errorf("error while Copy (%s): %w", debugDescription, err)
}
return nil
}
type halfReadCloser interface {
io.Reader
CloseRead() error
}
type halfWriteCloser interface {
io.Writer
CloseWrite() error
}
type halfCloser interface {
halfReadCloser
halfWriteCloser
}View on GitHub (pinned to 4f84911bfe)