{"record":{"id":"af27043e82f72c81","repo":"docker/compose","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":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compose/build_classic.go","lineNumber":196,"sourceCode":"\t\t\tdefer dockerfileCtx.Close() //nolint:errcheck\n\t\t}\n\tcase build.ContextTypeGit:\n\t\tvar tempDir string\n\t\ttempDir, relDockerfile, err = build.GetContextFromGitURL(specifiedContext, 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, specifiedContext, dockerfileName)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"unable to prepare context: %w\", err)\n\t\t}\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"unable to prepare context: path %q not found\", specifiedContext)\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, false)\n\t\tbuildCtx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/build_classic.go#L178-L214","documentation":"The default branch of the context-type switch: DetectContextType returned a value that is neither stdin, local, git, nor remote — in practice this happens when the context path does not exist on disk (DetectContextType classifies missing local paths into a 'not found' bucket). The message includes the offending path so the misconfiguration is obvious.","triggerScenarios":"`docker compose build` where `build.context` names a path that does not exist and cannot be classified — e.g. a directory never created, an interpolated empty/na variable producing '.', or a path with a typo after moving files.","commonSituations":"Running compose from the wrong working directory so relative contexts don't resolve; generated Compose files referencing build dirs that a generator step was supposed to create; Windows path separators in context values on Linux.","solutions":["Check that the exact path in the error exists: `ls -la '<path from message>'` from your compose invocation directory","Create the missing directory or correct the `build.context` value / the variable feeding it","Run compose from the repo root (or set `--project-directory`) so relative contexts resolve as intended"],"exampleFix":"# before\nservices:\n  app:\n    build:\n      context: ${APP_CTX}   # unset -> bad path\n\n# after\nservices:\n  app:\n    build:\n      context: ${APP_CTX:-./app}","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(svc.Build.Context); err != nil {\n    return fmt.Errorf(\"build context path %q not found — check working dir and interpolation\", svc.Build.Context)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fail fast in scripts: validate all context paths exist before calling compose build","Use absolute paths or ${VAR:-.} defaults for interpolated contexts"],"tags":["build","context","path","configuration"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}