How to fix unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat Dockerfile: no such file or directory in Docker

DockerBEGINNERLOWUpdated Dec 6, 2025· 225 views

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
  1. Verify the Dockerfile name and location
  2. Run docker build from the correct directory
  3. Check .dockerignore for accidentally excluded files
  4. Use -f flag for custom Dockerfile names
docker — error
# List files in current directory
ls -la
# Check for hidden extensions (common on Windows)
ls -la | grep -i docker
unable 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

  1. Dockerfile is named incorrectly (e.g., 'Dockerfile.txt', 'DockerFile', 'dockerfile')
  2. Running docker build from the wrong directory
  3. Dockerfile exists but wasn't committed to version control (git/CI issue)
  4. Dockerfile path is incorrect in docker-compose.yml
  5. File or directory is listed in .dockerignore
  6. Using a custom Dockerfile name without the -f flag
  7. 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"

1Verify the Dockerfile name and location

First, check that your Dockerfile exists and is named correctly:

bash
# List files in current directory
ls -la

# Check for hidden extensions (common on Windows)
ls -la | grep -i docker

The 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:

bash
# Remove .txt extension
mv Dockerfile.txt Dockerfile

# Fix capitalization
mv DockerFile Dockerfile
2Run docker build from the correct directory

The docker build command expects a build context directory. Ensure you're running it from the directory containing your Dockerfile:

bash
# 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:

bash
# Build with subdirectory as context
docker build -t myimage ./subdirectory
3Check .dockerignore for accidentally excluded files

If you have a .dockerignore file, it might be excluding your Dockerfile or required files:

bash
# View .dockerignore contents
cat .dockerignore

Common 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:

dockerignore
# Don't do this:
# Dockerfile
# **/Dockerfile

# Be specific about what to ignore
node_modules
*.log
.git
4Use -f flag for custom Dockerfile names

If you're using a non-standard Dockerfile name (e.g., Dockerfile.dev, Dockerfile.prod), you must specify it with the -f flag:

bash
# 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:

yaml
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile.dev
5Verify file is committed in version control

In CI/CD environments, this error often occurs when the Dockerfile wasn't committed:

bash
# Check git status
git status

# If Dockerfile is untracked, add it
git add Dockerfile
git commit -m "Add Dockerfile"
git push

Also verify the file exists in your remote repository:

bash
# List files in remote
git ls-tree -r HEAD --name-only | grep Dockerfile

In 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:

yaml
services:
  app:
    build:
      context: ./backend
      dockerfile: Dockerfile

Symlink 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