{"record":{"id":"8929487d01c248ce","repo":"docker/compose","slug":"checking-context-w","errorCode":null,"errorMessage":"checking context: %w","messagePattern":"checking context: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compose/build_classic.go","lineNumber":207,"sourceCode":"\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{\n\t\t\tExcludePatterns: excludes,\n\t\t\tChownOpts:       &archive.ChownOpts{UID: 0, GID: 0},\n\t\t})\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t}\n\n\t// replace Dockerfile if it was added from stdin or a file outside the build-context, and there is archive context\n\tif dockerfileCtx != nil && buildCtx != nil {\n\t\tbuildCtx, relDockerfile, err = build.AddDockerfileToBuildContext(dockerfileCtx, buildCtx)","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/build_classic.go#L189-L225","documentation":"Wraps build.ValidateContextDirectory, which walks the local context directory (after .dockerignore excludes) and verifies every file is usable for tarring. It fails when the walk hits unreadable files/directories (permission denied), or special entries that cannot be represented. The underlying walk error is chained after 'checking context:'.","triggerScenarios":"`docker compose build` (classic path, local context) where the context contains unreadable files not excluded by .dockerignore — root-owned artifacts from previous container runs, sockets/FIFOs in the build dir, or directories with mode 000.","commonSituations":"Building directly in a data dir where bind-mounted containers left root-owned files; node_modules or target/ with odd ownership after a containerized toolchain ran; leftover unix sockets in a context directory.","solutions":["Inspect the chained error for the offending path, then fix ownership/permissions (e.g. sudo chown -R $(id -u):$(id -g) <path>)","Add the problematic files/dirs to .dockerignore so they are excluded before validation","Clean stray build artifacts (sockets, root-owned temp files) out of the context directory"],"exampleFix":"# .dockerignore (after)\ndata/\n*.sock\ntmp/","handlingStrategy":"validation","validationCode":"// walk the context honoring .dockerignore and report unreadable entries early\nexcludes, _ := build.ReadDockerignore(ctxDir)\n_ = filepath.WalkDir(ctxDir, func(p string, d fs.DirEntry, err error) error {\n    if err != nil { return fmt.Errorf(\"%s: %w\", p, err) }\n    return nil\n})","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add root-owned or runtime artifacts (sockets, data dirs) to .dockerignore","Don't use directories that containers bind-mount into as build contexts"],"tags":["build","context","permissions","dockerignore"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}