How to fix unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat Dockerfile: no such file or directory in Docker
This error occurs when Docker cannot locate the Dockerfile during the build process. It typically happens when the Dockerfile is missing, misnamed, or not in the expected location within the build context.
Quick fix
Fixes unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat Dockerfile: no such file or directory
# List files in current directory
ls -la
# Check for hidden extensions (common on Windows)
ls -la | grep -i docker- Verify the Dockerfile name and location
- Run docker build from the correct directory
- Check .dockerignore for accidentally excluded files
- Use -f flag for custom Dockerfile names
# List files in current directoryls -la# Check for hidden extensions (common on Windows)ls -la | grep -i dockerunable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat Dockerfile: no such file or directory
What this error means
This error appears when you run `docker build` and Docker cannot find the Dockerfile in the build context. Docker looks for a file named exactly "Dockerfile" (capital D, lowercase f, no extension) in the directory you specify as the build context. The `lstat` system call is Docker's attempt to check if the Dockerfile exists at the expected path. When it fails with "no such file or directory," it means the file either doesn't exist, has the wrong name, or isn't accessible in the build context. Docker's build process requires the Dockerfile to be within the build context directory so it can parse the instructions and build your image. If the file is missing or misnamed, the build cannot proceed.
Typical symptoms
- Docker build command fails immediately before processing any layers
- Error message specifically mentions 'Dockerfile: no such file or directory'
- Build works on one machine but fails on another (often CI/CD)
- ls command shows the file exists but Docker still can't find it
Common causes
- Dockerfile is named incorrectly (e.g., 'Dockerfile.txt', 'DockerFile', 'dockerfile')
- Running docker build from the wrong directory
- Dockerfile exists but wasn't committed to version control (git/CI issue)
- Dockerfile path is incorrect in docker-compose.yml
- File or directory is listed in .dockerignore
- Using a custom Dockerfile name without the -f flag
- Case sensitivity issues on Linux systems
How to fix "unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat Dockerfile: no such file or directory"
First, check that your Dockerfile exists and is named correctly:
# List files in current directory
ls -la
# Check for hidden extensions (common on Windows)
ls -la | grep -i dockerThe file must be named exactly Dockerfile with:
- Capital 'D'
- Lowercase 'f'
- No file extension (.txt, .dockerfile, etc.)
If you see Dockerfile.txt or DockerFile, rename it:
# Remove .txt extension
mv Dockerfile.txt Dockerfile
# Fix capitalization
mv DockerFile DockerfileThe docker build command expects a build context directory. Ensure you're running it from the directory containing your Dockerfile:
# Navigate to your project directory
cd /path/to/your/project
# Build with current directory as context
docker build -t myimage .The dot (.) at the end is crucial—it tells Docker to use the current directory as the build context. Without it, you'll get a "requires exactly 1 argument" error.
If your Dockerfile is in a subdirectory:
# Build with subdirectory as context
docker build -t myimage ./subdirectoryIf you have a .dockerignore file, it might be excluding your Dockerfile or required files:
# View .dockerignore contents
cat .dockerignoreCommon mistake: copying patterns from .gitignore that exclude directories needed for the build.
Remove or comment out any lines that exclude your Dockerfile or required build files:
# Don't do this:
# Dockerfile
# **/Dockerfile
# Be specific about what to ignore
node_modules
*.log
.gitIf you're using a non-standard Dockerfile name (e.g., Dockerfile.dev, Dockerfile.prod), you must specify it with the -f flag:
# Build with custom Dockerfile name
docker build -f Dockerfile.dev -t myimage .
# Or with full path
docker build -f /path/to/custom/Dockerfile -t myimage .Note: The path specified with -f must still be within the build context directory.
For docker-compose, specify the dockerfile in your docker-compose.yml:
services:
app:
build:
context: .
dockerfile: Dockerfile.devIn CI/CD environments, this error often occurs when the Dockerfile wasn't committed:
# Check git status
git status
# If Dockerfile is untracked, add it
git add Dockerfile
git commit -m "Add Dockerfile"
git pushAlso verify the file exists in your remote repository:
# List files in remote
git ls-tree -r HEAD --name-only | grep DockerfileIn CI/CD pipelines, ensure your checkout step includes all files and doesn't have path filters excluding the Dockerfile.
Advanced notes
Docker Compose Context Issues: When using docker-compose, the build context is relative to the location of the docker-compose.yml file, not your current directory. If your Dockerfile is in a subdirectory, specify both context and dockerfile:
services:
app:
build:
context: ./backend
dockerfile: DockerfileSymlink Problems: The error message mentions "unable to evaluate symlinks"—if your Dockerfile is a symbolic link, Docker may have trouble following it depending on your OS and Docker version. Use a real file instead of a symlink when possible.
Case Sensitivity: Linux filesystems are case-sensitive. Dockerfile, dockerfile, and DockerFile are three different files. Windows and macOS are case-insensitive by default, which can cause issues when deploying to Linux-based CI/CD or production environments.
Build Context Size: If your build context is very large, Docker might timeout. While this doesn't directly cause the "no such file" error, it can manifest as build failures. Use .dockerignore to exclude unnecessary files.
Frequently asked questions
- What does "unable to prepare context: unable to evaluate symlinks in Dockerfile p" mean?
- This error appears when you run docker build and Docker cannot find the Dockerfile in the build context. Docker looks for a file named exactly "Dockerfile" (capital D, lowercase f, no extension) in the directory you specify as the build context. The lstat system call is Docker's attempt to check if the Dockerfile exists at the expected path.
- How do I fix "unable to prepare context: unable to evaluate symlinks in Dockerfile p"?
- This error occurs when Docker cannot locate the Dockerfile during the build process. It typically happens when the Dockerfile is missing, misnamed, or not in the expected location within the build context.
- What causes "unable to prepare context: unable to evaluate symlinks in Dockerfile p"?
- Dockerfile is named incorrectly (e.g., 'Dockerfile.txt', 'DockerFile', 'dockerfile') Running docker build from the wrong directory Dockerfile exists but wasn't committed to version control (git/CI issue)
- Is the "unable to prepare context: unable to evaluate symlinks in Dockerfile p" error serious?
- It is a low-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Docker Official Documentation
- 💬Docker unable to prepare context: unable to evaluate symlinks(Stack Overflow)
- 💬Docker build gives 'unable to prepare context' error(Stack Overflow)
- 📖Docker Docs - Dockerfile overview(Official Docs)
- 📖Docker Docs - Docker Build(Official Docs)
- 💬Docker build with -f option cannot find Dockerfile(Stack Overflow)