slimtoolkit/slim · error
invalid context directory
Error message
invalid context directory
What it means
ErrInvalidContextDir is thrown by pkg/app/master/builder/image_builder.go when the directory given as a Docker build context is not usable — it does not exist or is not a valid build context. NewBasicImageBuilder / the docker build flow validates the context directory before sending it to the Docker daemon, since building requires a readable context containing a Dockerfile.
Source
Thrown at pkg/app/master/builder/image_builder.go:22
"bytes"
"errors"
"fmt"
"path/filepath"
"strings"
"github.com/slimtoolkit/slim/pkg/app/master/config"
"github.com/slimtoolkit/slim/pkg/consts"
"github.com/slimtoolkit/slim/pkg/docker/dockerfile"
"github.com/slimtoolkit/slim/pkg/util/fsutil"
docker "github.com/fsouza/go-dockerclient"
log "github.com/sirupsen/logrus"
)
//todo: move/refactor this to be a "pkg/imagebuilder" engine
var (
ErrInvalidContextDir = errors.New("invalid context directory")
)
// BasicImageBuilder creates regular container images
type BasicImageBuilder struct {
ShowBuildLogs bool
BuildOptions docker.BuildImageOptions
APIClient *docker.Client
BuildLog bytes.Buffer
}
// ImageBuilder creates new optimized container images
type ImageBuilder struct {
BasicImageBuilder
RepoName string
AdditionalTags []string
ID string
Entrypoint []string
Cmd []stringView on GitHub (pinned to 81940d17fa)
Solutions
- Verify the ContextDir value passed to NewBasicImageBuilder exists and is a directory (os.Stat, MkdirAll if needed)
- Check file permissions on the directory so the process can read it
- Run the tool from the directory you intend to use as the build context, or pass an absolute path
Example fix
// before
opts := docker.BuildImageOptions{ContextDir: "./buid-context"}
// after
if _, err := os.Stat("./build-context"); err != nil {
os.MkdirAll("./build-context", 0755)
}
opts := docker.BuildImageOptions{ContextDir: "./build-context"} Defensive patterns
Strategy: validation
Validate before calling
info, err := os.Stat(ctxDir)
if err != nil || !info.IsDir() {
return fmt.Errorf("build context %q is not a directory", ctxDir)
} Prevention
- Always stat the context directory before invoking the builder
- Use absolute paths for ContextDir in scripts/CI
- Ensure the directory contains a Dockerfile
When it happens
Trigger: Calling dockerutils/build via NewBasicImageBuilder with BuildImageOptions.ContextDir pointing to a non-existent path, a file instead of a directory, or a directory without read permission.
Common situations: Typos in the --build-path/context-dir flag; running docker-slim from a different working directory than expected; CI checkouts that did not create the context dir; pointing at a Dockerfile file instead of its parent directory.
Related errors
AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31).
Data as JSON: /api/errors/2d5769303d4957a3.
Report an issue: GitHub.