Docker Error Guide: 'failed to read dockerfile: no such file or directory' — Fix Missing Dockerfile Path
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.
- #docker
- #troubleshooting
- #errors
- #dockerfile
Stuck on this Docker with AI error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
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 buildfails instantly withfailed 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 isDockerfile.prodorapp.dockerfilebut 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 buildfrom a directory that has no Dockerfile. - Case mismatch — the file is
dockerfile(lowercase) but tooling expectsDockerfile; the daemon’s filesystem is case-sensitive. -fpointing 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
Dockerfileat the repository root when you can, so the defaultdocker build .just works. - When you must use subfolders or alternate names, always pass
-fexplicitly in every build command and CI job. - Standardize on the capitalized
Dockerfilename 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.
Fixed it? Get 500 Docker with AI & 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.
Stuck on this? Start guided troubleshooting
Open an interactive diagnostic session with this error already loaded. Work a step-by-step plan, record what each check returns, land on a root cause, and export a clean incident summary — no account needed to start.
Did this fix your issue?
Solved it a different way?
Share the fix that worked for you — reviewed, then published to help the next engineer.
That looks like it may contain a secret (key, token, password, or connection string). Please remove it — a note with a detected secret can’t be published.
Thanks — that helps. Published notes appear after a quick review.
Trending errors this week
The error guides other engineers are actually reading right now.
- 1mount: wrong fs type, bad option, bad superblock
- 2Docker 'failed to set up container networking': Fix the Bridge and IP Pool
- 3Docker 'failed to create shim task': How to Fix the containerd Runtime Error
- 4Transport endpoint is not connected
- 5modprobe: FATAL: Module not found
- 6mount: wrong fs type, bad option, bad superblock
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.