{"record":{"id":"327408fba74be08d","repo":"docker/cli","slug":"unable-to-prepare-context-path-q-not-found","errorCode":null,"errorMessage":"unable to prepare context: path %q not found","messagePattern":"unable to prepare context: path %q not found","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/image/build.go","lineNumber":264,"sourceCode":"\t\t\tdefer dockerfileCtx.Close()\n\t\t}\n\tcase build.ContextTypeGit:\n\t\tvar tempDir string\n\t\ttempDir, relDockerfile, err = build.GetContextFromGitURL(options.context, options.dockerfileName)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to prepare context: %w\", err)\n\t\t}\n\t\tdefer func() {\n\t\t\t_ = os.RemoveAll(tempDir)\n\t\t}()\n\t\tcontextDir = tempDir\n\tcase build.ContextTypeRemote:\n\t\tbuildCtx, relDockerfile, err = build.GetContextFromURL(progBuff, options.context, options.dockerfileName)\n\t\tif err != nil && options.quiet {\n\t\t\t_, _ = fmt.Fprintln(dockerCli.Err(), progBuff)\n\t\t}\n\tdefault:\n\t\treturn fmt.Errorf(\"unable to prepare context: path %q not found\", options.context)\n\t}\n\n\t// read from a directory into tar archive\n\tif buildCtx == nil {\n\t\texcludes, err := build.ReadDockerignore(contextDir)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif err := build.ValidateContextDirectory(contextDir, excludes); err != nil {\n\t\t\treturn fmt.Errorf(\"checking context: %w\", err)\n\t\t}\n\n\t\t// And canonicalize dockerfile name to a platform-independent one\n\t\trelDockerfile = filepath.ToSlash(relDockerfile)\n\n\t\texcludes = build.TrimBuildFilesFromExcludes(excludes, relDockerfile, options.dockerfileFromStdin())\n\t\tbuildCtx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/image/build.go#L246-L282","documentation":"Returned by runBuild (build.go:264) in the default branch of the context-type switch, meaning build.DetectContextType returned a value that is none of stdin, local, git, or remote. In practice DetectContextType classifies any non-URL, non-git, non-'-' argument as local, so reaching the default branch implies the path does not exist as a local file/dir and did not match the other detectors - effectively an unrecognized/missing context argument.","triggerScenarios":"Passing a build context argument that is not a directory, not '-', not a URL, and not a git URL, yet also does not exist on the filesystem so that it was not classified as local. This is rare because most non-existent paths still fall into the local branch and fail later at 331; the default branch is reached for truly unclassified inputs (e.g., unusual schemes or future context types).","commonSituations":"Using an unsupported URL scheme (e.g., 'ftp://...'); passing a path with characters that defeat the local detector; version mismatch where a newer context type is not handled by this CLI build; extremely unusual inputs like empty strings in some edge cases.","solutions":["Confirm the context argument is a supported type: local directory path, '-', git URL (https/ssh), or http(s) URL.","If it is meant to be a local path, verify it exists: 'ls <path>'.","For URL contexts, use http(s):// or git-compliant URLs only.","Upgrade the CLI if you expect a newer context type (e.g., a new scheme) to be recognized."],"exampleFix":"# before (unsupported scheme)\ndocker build ftp://example.com/repo\n# after (https URL or local path)\ndocker build https://example.com/repo.git\ndocker build ./myapp","handlingStrategy":"validation","validationCode":"// Classify a context argument before passing it to docker build.\nfunc classifyContext(arg string) error {\n\tswitch {\n\tcase arg == \"-\":\n\t\treturn nil\n\tcase strings.HasPrefix(arg, \"http://\"), strings.HasPrefix(arg, \"https://\"), strings.HasPrefix(arg, \"git@\"), strings.HasPrefix(arg, \"git://\"):\n\t\treturn nil\n\tcase fileExists(arg):\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported context: %q\", arg)\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := buildCmd.Execute(); err != nil {\n\tif strings.Contains(err.Error(), \"path\") && strings.Contains(err.Error(), \"not found\") {\n\t\t// context argument is neither a local path nor a supported URL\n\t}\n}","preventionTips":["Use a local directory, '-', an http(s) URL, or a git URL as the build context.","Verify the path exists before building.","Upgrade the CLI if you need a newer context type."],"tags":["build","context","unsupported","validation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}