Error when running docker build on any dockerfile: "unable to prepare context: unable to evaluate symlinks in Dockerfile path"

Solution 1:

I see this question being asked at a number of places. Well I think I found the solution.

In earlier versions, the DockerFile was named with a capital 'F'. However in the latest releases, the DockerFile is recognized only if contains a small 'f'.

I recently upgraded the docker [Docker version 17.09.1-ce, build 19e2cf6 on CentOS 7] and found that

docker build -t someapp .

Fails if the current directory contains the file DockerFile, but works well if it contains Dockerfile

Solution 2:

In your current directory run command "ls" and see what file extension is with Dockerfile. If you have an extension you need to specify the full path to the Dockerfile.abc

Else you can create a blank Dockerfile WITHOUT an extension using "TextWrangler" (available for mac) and then run the command

docker image build -t yourname/firstapp .

I hope you have already resolved the issue; sharing this for future visitors :) attached is the terminal screenshot with solution

enter image description here

Solution 3:

Try this syntax for building the docker image using docker build, on docker version 20.10.5, build 55c4c88, on Ubuntu 20.0.4 LTS-March 2021:

$ docker build -t <containername> . -f <whateverthedockerfilename>.Dockerfile

EXPLANATION:

Whenever your're using the command 'docker build', if you do not explicitly specify the dockerfile name from which you want to build your docker image, then, by default, the docker engine will look for a Dockerfile with the name 'Dockerfile.Dockerfile' in your original working directory, instead of looking for a particular Dockerfile with the extension '.Dockerfile'.

As a result, whenever the docker engine cannot locate the file 'Dockerfile.Dockerfile', it throws the error "unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/xxx/yyy/Dockerfile: no such file or directory."

Therefore, to get things running, just specify the exact name of your dockerfile as labeled in your directory.

It should be OK.

Cheers!