docker/cli · error

unexpected '\\' in path

Error message

unexpected '\\' in path

What it means

Returned by isValidFilePath during context Import when a tar/zip archive entry's name contains a backslash character. Docker context archives must use POSIX-style forward-slash paths; a backslash indicates a Windows-style path or a crafted entry that path.Clean would not normalize, so the importer rejects it defensively before extracting.

Solutions

  1. Re-export the context on the original host with docker context export (it always emits forward slashes) and import that archive instead.
  2. Inspect the archive with tar -tvf / unzip -l and rewrite any entry names containing backslashes to forward slashes using a repacking tool.
  3. Avoid creating context archives manually; only use docker context export/import round-trips.

Example fix

// before: manual zip on Windows emits 'tls\docker\cert.pem'
// after: repack with forward-slash paths
//   tar -tf ctx.tar | sed 's/\\/\//g'  # verify, then repack
//   or simply: docker context export <src> && docker context import <dst> < ctx.dockercontext
Defensive patterns

Strategy: validation

Validate before calling

// Validate archive entries before calling store.Import
func validateArchiveEntries(r io.Reader) error {
	tr := tar.NewReader(r)
	for {
		hdr, err := tr.Next()
		if err == io.EOF { break }
		if err != nil { return err }
		if strings.Contains(hdr.Name, `\`) {
			return fmt.Errorf("entry %q contains a backslash", hdr.Name)
		}
	}
	return nil
}

Prevention

When it happens

Trigger: Calling store.Import (docker context import) with an archive produced on Windows by a tool that emitted backslash separators, or a hand-crafted/malicious archive where an entry name contains '\'. The check at store.go:378 fires after the path-format and prefix validations pass.

Common situations: Zipping a context directory on Windows with built-in tools that preserve native separators; archiving files where the TLS endpoint subfolder name accidentally includes a backslash; transferring a context between Windows and Linux hosts.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/0c4315ca0ceec550. Report an issue: GitHub.

Appendix: source

Thrown at cli/context/store/store.go:379

	}
	switch importContentType {
	case zipType:
		return importZip(name, s, r)
	default:
		// Assume it's a TAR (TAR does not have a "magic number")
		return importTar(name, s, r)
	}
}

func isValidFilePath(p string) error {
	if p != metaFile && !strings.HasPrefix(p, "tls/") {
		return errors.New("unexpected context file")
	}
	if path.Clean(p) != p {
		return errors.New("unexpected path format")
	}
	if strings.Contains(p, `\`) {
		return errors.New(`unexpected '\' in path`)
	}
	return nil
}

func importTar(name string, s Writer, reader io.Reader) error {
	tr := tar.NewReader(&limitedReader{R: reader, N: maxAllowedFileSizeToImport})
	tlsData := ContextTLSData{
		Endpoints: map[string]EndpointTLSData{},
	}
	var importedMetaFile bool
	for {
		hdr, err := tr.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			return err
		}

View on GitHub (pinned to 4f84911bfe)