slimtoolkit/slim · error
invalid context directory - %s
Error message
invalid context directory - %s
What it means
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.
Source
Thrown at pkg/app/master/compose/execution.go:1194
}
//TODO: investigate []string to string
if len(config.ExtraHosts) > 0 {
buildOptions.ExtraHosts = config.ExtraHosts[0]
}
if strings.HasPrefix(config.Context, "http://") || strings.HasPrefix(config.Context, "https://") {
buildOptions.Remote = config.Context
} else {
contextDir := config.Context
if !strings.HasPrefix(contextDir, "/") {
contextDir = filepath.Join(basePath, contextDir)
}
if info, err := os.Stat(contextDir); err == nil && info.IsDir() {
buildOptions.ContextDir = contextDir
} else {
return fmt.Errorf("invalid context directory - %s", contextDir)
}
}
if err := apiClient.BuildImage(buildOptions); err != nil {
log.Debugf("buildImage: dockerapi.BuildImage() error = %v", err)
return err
}
fmt.Println("build output:")
fmt.Println(output.String())
fmt.Println("build output [DONE]")
return nil
}
func durationToSeconds(d *types.Duration) int {
if d == nil {
return 0View on GitHub (pinned to 81940d17fa)
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
Example fix
// before (docker-compose.yml)
app:
build:
context: ./sr # typo, directory missing
// after
app:
build:
context: ./src Defensive patterns
Strategy: validation
Validate before calling
func checkBuildContext(baseDir string, svc types.ServiceConfig) error {
if svc.Build == nil {
return nil
}
ctx := svc.Build.Context
if !filepath.IsAbs(ctx) {
ctx = filepath.Join(baseDir, ctx)
}
info, err := os.Stat(ctx)
if err != nil || !info.IsDir() {
return fmt.Errorf("build context %q does not exist or is not a dir", ctx)
}
return nil
} Try / catch
if err := compose.BuildImage(ctx, cli, baseDir, imgName, buildCfg); err != nil {
if strings.HasPrefix(err.Error(), "invalid context directory") {
return fmt.Errorf("fix build.context path: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- invalid context directory
- no service image
- no project info
- unknown service - %s
- cant build service image - %s
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/8dac4b9d51e93d76.
Report an issue: GitHub.