7

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.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
OpenBSDNinja
  • 181
  • 1
  • 1
  • 5

3 Answers3

10

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

Akash
  • 101
  • 1
  • 2
3

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

sebix
  • 4,313
  • 2
  • 29
  • 47
Adil
  • 31
  • 2
2

Try the following 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 start looking for a Dockerfile with the default name 'Dockerfile.Dockerfile' in your original working directory, instead of looking for any Dockerfile with the extension '.Dockerfile'.

Therefore, in such cases, whenever the docker engine cannot locate the file 'Dockerfile.Dockerfile', it will understandably throw the error "unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/xxx/yyy/Dockerfile: no such file or directory."

So to get things running, you just need to specify the correct name of your dockerfile as labelled in your original directory and BAM IT SHOULD WORK! ‍

Cheers!