{"record":{"id":"8dac4b9d51e93d76","repo":"slimtoolkit/slim","slug":"invalid-context-directory-s","errorCode":null,"errorMessage":"invalid context directory - %s","messagePattern":"invalid context directory - (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/compose/execution.go","lineNumber":1194,"sourceCode":"\t}\n\n\t//TODO: investigate []string to string\n\tif len(config.ExtraHosts) > 0 {\n\t\tbuildOptions.ExtraHosts = config.ExtraHosts[0]\n\t}\n\n\tif strings.HasPrefix(config.Context, \"http://\") || strings.HasPrefix(config.Context, \"https://\") {\n\t\tbuildOptions.Remote = config.Context\n\t} else {\n\t\tcontextDir := config.Context\n\t\tif !strings.HasPrefix(contextDir, \"/\") {\n\t\t\tcontextDir = filepath.Join(basePath, contextDir)\n\t\t}\n\n\t\tif info, err := os.Stat(contextDir); err == nil && info.IsDir() {\n\t\t\tbuildOptions.ContextDir = contextDir\n\t\t} else {\n\t\t\treturn fmt.Errorf(\"invalid context directory - %s\", contextDir)\n\t\t}\n\t}\n\n\tif err := apiClient.BuildImage(buildOptions); err != nil {\n\t\tlog.Debugf(\"buildImage: dockerapi.BuildImage() error = %v\", err)\n\t\treturn err\n\t}\n\n\tfmt.Println(\"build output:\")\n\tfmt.Println(output.String())\n\tfmt.Println(\"build output [DONE]\")\n\n\treturn nil\n}\n\nfunc durationToSeconds(d *types.Duration) int {\n\tif d == nil {\n\t\treturn 0","sourceCodeStart":1176,"sourceCodeEnd":1212,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/compose/execution.go#L1176-L1212","documentation":"buildImage resolves the build context directory for a service's build config; if the resolved contextDir (joined with the base compose dir when relative) does not exist or is not a directory per os.Stat, it returns 'invalid context directory - %s'. The image build cannot proceed without a valid context directory.","triggerScenarios":"Building a service whose `build.context` points to a nonexistent path, a file instead of a directory, or a path that is wrong once joined with the base compose dir (relative paths resolved against the wrong base).","commonSituations":"Typos in build.context; running the tool from a different working directory than expected; a Dockerfile directory deleted or renamed; using an absolute path valid on another machine; missing volume mount in containerized runs.","solutions":["Fix the `build.context` path in the compose file so it points to an existing directory relative to the compose file's directory","Verify the directory exists with ls/os.stat at the resolved location (base compose dir + context)","If running from a different cwd or inside a container, ensure the base compose directory and the build context are accessible/mounted"],"exampleFix":"// before (docker-compose.yml)\n  app:\n    build:\n      context: ./sr          # typo, directory missing\n// after\n  app:\n    build:\n      context: ./src","handlingStrategy":"validation","validationCode":"func checkBuildContext(baseDir string, svc types.ServiceConfig) error {\n    if svc.Build == nil {\n        return nil\n    }\n    ctx := svc.Build.Context\n    if !filepath.IsAbs(ctx) {\n        ctx = filepath.Join(baseDir, ctx)\n    }\n    info, err := os.Stat(ctx)\n    if err != nil || !info.IsDir() {\n        return fmt.Errorf(\"build context %q does not exist or is not a dir\", ctx)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := compose.BuildImage(ctx, cli, baseDir, imgName, buildCfg); err != nil {\n    if strings.HasPrefix(err.Error(), \"invalid context directory\") {\n        return fmt.Errorf(\"fix build.context path: %w\", err)\n    }\n    return err\n}","preventionTips":["Use paths relative to the compose file location and verify they exist","Run `docker compose config` to see resolved build contexts","When running in containers, mount the build context directory","Commit Dockerfile directories to the repo so they always exist"],"tags":["compose","docker","build-context"],"backgroundTag":"invalid-build-context","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}