{"record":{"id":"90a05e2e366b7824","repo":"docker/cli","slug":"unable-to-prepare-context-w","errorCode":null,"errorMessage":"unable to prepare context: %w","messagePattern":"unable to prepare context: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/image/build.go","lineNumber":252,"sourceCode":"\t\t}\n\tcase build.ContextTypeLocal:\n\t\tcontextDir, relDockerfile, err = build.GetContextFromLocalDir(options.context, options.dockerfileName)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"unable to prepare context: %s\", err)\n\t\t}\n\t\tif strings.HasPrefix(relDockerfile, \"..\"+string(filepath.Separator)) {\n\t\t\t// Dockerfile is outside build-context; read the Dockerfile and pass it as dockerfileCtx\n\t\t\tdockerfileCtx, err = os.Open(options.dockerfileName)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"unable to open Dockerfile: %w\", err)\n\t\t\t}\n\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 {","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/image/build.go#L234-L270","documentation":"Returned by runBuild (build.go:252) when build.GetContextFromGitURL fails while preparing a git-URL build context (ContextTypeGit). This clones/fetches the remote git repository into a temp directory and locates the Dockerfile within it. Failure indicates the git operation or subsequent Dockerfile resolution failed.","triggerScenarios":"Running 'docker build https://github.com/org/repo.git[#:subdir]' or 'docker build git@...' where the URL is unreachable, the repo does not exist, authentication fails, the referenced subdir/branch does not exist, or git is not installed on PATH. Also fires if the cloned repo contains no Dockerfile at the expected path.","commonSituations":"Private repo without configured credentials/SSH key; typo in the URL; branch/tag referenced after '#' does not exist; corporate proxy/firewall blocking git; git binary missing or too old; the repo has no Dockerfile in the root or specified subdir.","solutions":["Clone the repo manually first to validate access: 'git clone <url>' and confirm it succeeds.","Ensure credentials are configured (SSH key, credential helper, or HTTPS token) for private repos.","Verify the #:path and #:branch fragment syntax matches actual branches/dirs in the repo.","Confirm git is installed and reachable: 'git --version'."],"exampleFix":"# before (private repo, no credentials)\ndocker build git@github.com:org/private.git\n# after (configure SSH key, or clone then build locally)\ngit clone git@github.com:org/private.git && docker build private","handlingStrategy":"validation","validationCode":"// Probe git access for a remote context URL before building.\nfunc validateGitContext(url string) error {\n\tcmd := exec.Command(\"git\", \"ls-remote\", url)\n\treturn cmd.Run()\n}","typeGuard":null,"tryCatchPattern":"if err := buildCmd.Execute(); err != nil {\n\tif strings.Contains(err.Error(), \"unable to prepare context\") && strings.HasPrefix(ctx, \"http\") {\n\t\t// git context fetch failed; verify credentials and network\n\t}\n}","preventionTips":["Run 'git ls-remote <url>' to validate access before building from a git URL.","Configure SSH keys or credential helpers for private repos.","Confirm the branch/subdir fragment in the URL exists."],"tags":["build","git-context","network","authentication"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}