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.
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.
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.
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.
dockerfile parse error line 5: unknown instruction: RRUN
How to fix 'unknown instruction' Dockerfile parse error in Docker
Error response from daemon: manifest for nginx:nonexistent not found: manifest unknown: manifest unknown
How to fix 'manifest for image:tag not found' in Docker
Error response from daemon: invalid reference format: repository name must be lowercase
How to fix 'repository name must be lowercase' in Docker
Error response from daemon: No such image
How to fix 'No such image' in Docker
Error response from daemon: Container is not running
How to fix 'Container is not running' when using docker exec