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

Posted on

A server stack is the collection of software that forms the operational infrastructure on a given machine. In a computing context, a stack is an ordered pile. A server stack is one type of solution stack — an ordered selection of software that makes it possible to complete a particular task. Like in this post about Error when running docker build on any dockerfile: “unable to prepare context: unable to evaluate symlinks in Dockerfile path” was one problem in server stack that need for a solution. Below are some tips in manage your linux server when you find problem about linux, docker, ubuntu-16.04, , .

I’m running :

$ docker build -t somefile .

Every time I run that I get this error:

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat 

The full error is:

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/someusername/code/Dockerfile: no such file or directory

I thought this had to do with the docker version I’m using, so upgraded to the latest version using this guide:
Install Latest docker version. I still get the same error.
I’ve tried different docker versions. I’ve tried on different servers.
I’ve even tried different docker files.

The last server I tried on I was using this version of docker:

Docker version 17.03.1-ce, build c6d412e

Not sure where I’m going wrong. Need a sanity check please.

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

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

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:

When using the command ‘docker build’, if you do not explicitly specify the Dockerfile from which you want to build your docker image, then the docker engine, by DEFAULT, will look for a Dockerfile with the filename ‘Dockerfile.Dockerfile’ in your original working directory, instead of a Dockerfile with the extension ‘.Dockerfile’.

Thus, whenever the docker engine cannot locate the file ‘Dockerfile.Dockerfile’, it will throw 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, you simply need to specify the correct name of your Dockerfile as labeled in your directory.

It should be working fine post this!

Hoping this helps!


PS:
Kudos to Akash’s answer for pointing out above as from which docker version does the problem arise [https://serverfault.com/questions/856452/error-when-running-docker-build-on-any-dockerfile-unable-to-prepare-context-u/888666#888666].

Leave a Reply

Your email address will not be published.