Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

docker build cannot find the Dockerfile it was told to use

Errorunable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx

Short answer

docker build looks for a file named Dockerfile at the root of the build context, the folder you pass as the last argument. Both errors mean no file was found where Docker looked. Run the build from the folder that holds the Dockerfile, or pass the context folder and the -f flag so they match what is on disk.

  • Applies to Docker Engine 28, Docker Desktop 4.x, Docker Buildx 0.2x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the folder you are building from, and look for a file called exactly Dockerfile. The context is the last argument of the command, so print the command you ran next to it.

    ls -la
    # Windows PowerShell: dir
    docker build .
  2. 2Match what you see, then jump to its fix

    1. 1The context folder (often just .) has no Dockerfile in it. The file may sit in a sub-folder, or carry a different name.There is no file named Dockerfile at the root of the contextFix
    2. 2The error appears only when the command has -f or --file.-f points at a file that is not where you typed itFix

What does the error look like?

  • unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx
  • ERROR [internal] load build definition from Dockerfile

Cause 1 of 2

There is no file named Dockerfile at the root of the context

1Check

Docker only looks for PATH/Dockerfile when -f is not given. A file named dockerfile.txt, Dockerfile.dev or a Dockerfile inside backend/ is not found unless you say so.

ls -la

2Fix

Go to the folder that contains the Dockerfile and build there, or pass that folder as the context.

cd backend
docker build -t my-app .
# or, from the parent folder
docker build -t my-app backend

3Verify

The build now starts reading the Dockerfile instead of stopping at once.

docker build -t my-app .

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 2

-f points at a file that is not where you typed it

1Check

-f selects a Dockerfile other than the default. Check the spelling and the path you gave it, and which folder you ran the command from.

docker build -f docker/app.Dockerfile -t my-app .
ls docker/app.Dockerfile

2Fix

Correct the -f value to a file that exists, and keep the context argument as the folder the COPY lines expect.

docker build -f docker/app.Dockerfile -t my-app .

3Verify

The command moves past load build definition and starts the first step.

docker build -f docker/app.Dockerfile -t my-app .

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Keep one Dockerfile at the repository root, or write the -f path into your Makefile or CI step so nobody types it by hand.
  • Build from the folder you intend to use as the context, and print that folder in CI logs.
  • On Windows, turn on file extensions in Explorer so a Dockerfile is not saved as Dockerfile.txt.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.