{"record":{"id":"995ffa5ea7e090a3","repo":"wagoodman/dive","slug":"could-not-find-containerfile-or-dockerfile","errorCode":null,"errorMessage":"could not find Containerfile or Dockerfile\n","messagePattern":"could not find Containerfile or Dockerfile\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dive/image/docker/build.go","lineNumber":83,"sourceCode":"\t\tdefaultContainerfileName,                  // Containerfile\n\t\tstrings.ToLower(defaultContainerfileName), // containerfile\n\t\tdefaultDockerfileName,                     // Dockerfile\n\t\tstrings.ToLower(defaultDockerfileName),    // dockerfile\n\t}\n\n\tfor _, arg := range buildArgs {\n\t\tfileInfo, err := fs.Stat(arg)\n\t\tif err == nil && fileInfo.IsDir() {\n\t\t\tfor _, candidate := range candidates {\n\t\t\t\tfilePath := filepath.Join(arg, candidate)\n\t\t\t\tif exists, _ := afero.Exists(fs, filePath); exists {\n\t\t\t\t\treturn filePath, nil\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn \"\", fmt.Errorf(\"could not find Containerfile or Dockerfile\\n\")\n}\n","sourceCodeStart":65,"sourceCodeEnd":85,"githubUrl":"https://github.com/wagoodman/dive/blob/d6c691947f8fda635c952a17ee3b7555379d58f0/dive/image/docker/build.go#L65-L85","documentation":"Returned by tryFindContainerfile (dive/image/docker/build.go:83) when no build argument resolves to a directory containing a known container recipe. The search is strict: for each arg that Stats as a directory it checks exactly Containerfile, containerfile, Dockerfile, dockerfile (filepath.Join'd onto that directory). No -f equivalent exists, and non-directory args are ignored entirely.","triggerScenarios":"Running dive --build with build args that name a file (e.g. 'dive --build -f Dockerfile.custom .') - files are never opened as recipes; pointing at a directory whose recipe has a custom name (Dockerfile.dev, docker/Dockerfile); an empty or misspelled build-context path.","commonSituations":"Monorepos where the Dockerfile lives in a parent dir or is renamed per-service; CI running dive from a different working directory than the build context; users expecting buildkit-style -f semantics from dive.","solutions":["cd into (or pass) the directory that directly contains Dockerfile or Containerfile - exact names only","Rename or symlink your custom recipe to Dockerfile/Containerfile for the dive build step","Prefer building with docker/podman directly and pointing dive at the result (dive docker://<image>) to avoid the file-discovery limitation","Note -f/--file is not honored by this finder regardless of flags passed"],"exampleFix":"# before\ndive build-image --build -f Dockerfile.prod .\n\n# after\ncp Dockerfile.prod ./Dockerfile && dive build-image --build .\n# or: build externally, then analyze\ndocker build -f Dockerfile.prod -t app:ci . && dive docker://app:ci","handlingStrategy":"validation","validationCode":"// check for a discoverable recipe before invoking the build\ncandidates := []string{\"Containerfile\", \"containerfile\", \"Dockerfile\", \"dockerfile\"}\nfound := false\nfor _, c := range candidates {\n    if _, err := os.Stat(filepath.Join(ctxDir, c)); err == nil {\n        found = true\n        break\n    }\n}\nif !found {\n    return fmt.Errorf(\"no Containerfile/Dockerfile in %s; build externally instead\", ctxDir)\n}","typeGuard":null,"tryCatchPattern":"err := builder.Build(ctx, buildArgs)\nif err != nil && strings.Contains(err.Error(), \"could not find Containerfile or Dockerfile\") {\n    // fall back to an explicit docker build + dive on the result\n    _ = run(\"docker\", append([]string{\"build\", \"-t\", tag, ctxDir}, buildArgs...)...)\n    return diveImage(\"docker://\" + tag)\n}","preventionTips":["Name your recipe exactly Dockerfile or Containerfile at the context root","Remember dive's finder ignores custom filenames (-f is not supported)","Prefer building with docker/podman and analyzing the tagged image"],"tags":["build","dockerfile","discovery","cli"],"backgroundTag":null,"analyzedSha":"d6c691947f8fda635c952a17ee3b7555379d58f0","analyzedAt":"2026-08-15T09:42:35.293Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}