Skip to content
DevOps AI ToolKit
Newsletter
All guides
Docker with AI By James Joyner IV · · 8 min read

Docker Error Guide: 'failed to read dockerfile: no such file or directory' — Fix Missing Dockerfile Path

Quick answer

Fix 'failed to read dockerfile: open /Dockerfile: no such file or directory' in Docker: point -f at the right file, fix the build context, and check casing.

Part of the Docker Build & Image Errors hub
  • #docker
  • #troubleshooting
  • #errors
  • #dockerfile
Free toolkit

Fixing errors like this? Get 500 free DevOps AI prompts

500 copy-paste AI prompts for the stack you actually run — one PDF, free.

Overview

The build fails before parsing because Docker cannot locate a Dockerfile in the build context:

failed to read dockerfile: open /Dockerfile: no such file or directory

By default docker build . looks for a file literally named Dockerfile at the root of the build context. If the file is named differently, lives in a subdirectory, or the context points somewhere unexpected, the daemon has nothing to read and stops immediately.

Symptoms

  • docker build fails instantly with failed to read dockerfile.
  • The build never sends layers or runs steps.
  • The Dockerfile exists but under a different name (Dockerfile.prod, dockerfile, Containerfile).
  • The command works in one directory but not another.

Common Root Causes

  • Non-default filename without -f — the file is Dockerfile.prod or app.dockerfile but the command does not pass -f.
  • Dockerfile in a subdirectory — it lives in docker/ while the build runs from the repo root without -f.
  • Wrong build context — running docker build from a directory that has no Dockerfile.
  • Case mismatch — the file is dockerfile (lowercase) but tooling expects Dockerfile; the daemon’s filesystem is case-sensitive.
  • -f pointing outside the context — the Dockerfile path must be resolvable relative to the context (or an absolute path with BuildKit).
  • Missing file — it was never created, or was removed/renamed.

Diagnostic Workflow

Confirm where you are and whether a Dockerfile exists there:

pwd
ls -la Dockerfile

Search the repository for any Dockerfile-like files, including alternate names and subdirectories:

find . -maxdepth 3 -iname 'Dockerfile*' -o -iname '*.dockerfile'

Point -f at the actual file and pass the correct context as the final argument:

docker build -f docker/Dockerfile.prod -t myapp:1.4.2 .

Re-run with a plain progress log to confirm the resolved Dockerfile path:

docker build --progress=plain -f docker/Dockerfile.prod -t myapp:1.4.2 .

Example Root Cause Analysis

A developer moved Docker assets into a folder and builds broke:

failed to read dockerfile: open /Dockerfile: no such file or directory

find . -maxdepth 3 -iname 'Dockerfile*' showed:

./docker/Dockerfile

The Dockerfile had been relocated to docker/, but the build command was still the bare docker build -t myapp:1.4.2 ., which looks for ./Dockerfile at the context root. Docker found no file to read. The fix was to name the file explicitly while keeping the context at the repo root so COPY paths still resolve:

docker build -f docker/Dockerfile -t myapp:1.4.2 .

The build then read the correct file. The rule: -f selects the Dockerfile; the trailing argument selects the context — they are independent.

Prevention Best Practices

  • Keep a Dockerfile at the repository root when you can, so the default docker build . just works.
  • When you must use subfolders or alternate names, always pass -f explicitly in every build command and CI job.
  • Standardize on the capitalized Dockerfile name to avoid case-sensitivity issues across platforms.
  • Document the exact build command (context + -f) in the README so nobody guesses.
  • Remember: the context (last argument) and the Dockerfile path (-f) are set separately — set both deliberately.

Quick Command Reference

pwd                                          # confirm current directory
ls -la Dockerfile                            # check for the default file
find . -maxdepth 3 -iname 'Dockerfile*'      # locate any Dockerfile
docker build -f docker/Dockerfile -t myapp:1.4.2 .
docker build --progress=plain -f docker/Dockerfile.prod -t myapp:1.4.2 .

Conclusion

failed to read dockerfile: no such file or directory simply means Docker looked for a Dockerfile and found none at the expected path. Confirm the file’s real name and location, then pass it with -f while keeping the context at the repo root. A root-level Dockerfile or an explicit -f in every command eliminates the error. See more build fixes in the Docker stack guides.

Free download · 368-page PDF

Get 500 Battle-Tested DevOps AI Prompts — Free

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.