Docker - unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx
Asked Answered
P

43

369

I just downloaded Docker Toolbox for Windows 10 64-bit today. I'm going through the tutorial. I'm receiving the following error when trying to build an image using a Dockerfile.

Steps:

  • Launched Docker Quickstart terminal.
  • testdocker after creating it.
  • Prepare Dockerfile as documented in "Build your own image" web link
  • ran the below command

docker build -t docker-whale .

Error: $ docker build -t docker-whale .

unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx C:\Users\Villanueva\Test\testdocker\Dockerfile: The system cannot find the file specified.

BTW: I tried several options mentioned @ https://github.com/docker/docker/issues/14339

docker info

Output:

Containers: 4
 Running: 0
 Paused: 0
 Stopped: 4
Images: 2
Server Version: 1.10.1
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 20
 Dirperm1 Supported: true
Execution Driver: native-0.2
Logging Driver: json-file
Plugins:
 Volume: local
 Network: bridge null host
Kernel Version: 4.1.17-boot2docker
Operating System: Boot2Docker 1.10.1 (TCL 6.4.1); master : b03e158 - Thu Feb 11 22:34:01 UTC 2016
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 996.2 MiB
Name: default
ID: C7DS:CIAJ:FTSN:PCGD:ZW25:MQNG:H3HK:KRJL:G6FC:VPRW:SEWW:KP7B
Debug mode (server): true
 File Descriptors: 32
 Goroutines: 44
 System Time: 2016-02-19T17:37:37.706076803Z
 EventsListeners: 0
 Init SHA1:
 Init Path: /usr/local/bin/docker
 Docker Root Dir: /mnt/sda1/var/lib/docker
Labels:
 provider=virtualbox
Particularism answered 19/2, 2016 at 17:48 Comment(4)
Update: docker build -t XXX --file ./Dockefile . worked. Docker may want to update their documentation for Windows users.Particularism
If docker build -t XXX --file ./Dockefile it might be because you got the filename wrong it's missing the R.Karol
This is an amazingly bad error message, it just means "cannot open file" - same on Linux and macOS.Wonderful
Mind-blowingly bad error message.Tamarisk
F
343

While executing the following command,

docker build -t docker-whale .

check that Dockerfile is present in your current working directory.

Findley answered 14/7, 2016 at 10:0 Comment(10)
Thanks. My issue was I had created my Dockerfile in Notepad and it had automatically appended .txt to the filename.Electrical
You may also explicitly write the Dockerfile name with the fflag, as in docker build -f Dockerfile-dev.yaml -t my_container . This may prove useful if you have several Dockerfile in your project, one per environment, for example. The same applies to docker-compose. Putting them in different subdirectories will not work, since the context (.) will not match.Cadwell
@Electrical I wish I could give you more points for that. That was exactly my problem too!Hokusai
Notepad is an excessively evil program.Newlywed
When you need a reminder that you're calling from the wrong directory xDPied
Copied something weird after the trailing period, removing this helped.Aime
Well, I have it in my current dir but still have the error.Leung
Your Expansion really makes sense. my file was called docker, which led to this error but your solution was really helpful. big upsRussellrusset
@SumiStraessle Thank you, this was exactly my problem. Docker oddly seems to assume you will name every dockerfile "Dockerfile".Tying
you're quite welcome.Cadwell
C
248

The error message is misleading

The problem has nothing to do with symbolic links really. Usually, the problem is only that Docker cannot find the Dockerfile describing the build.

Typical reasons are these:

  • Dockerfile has wrong name. It must be called Dockerfile. If it is called, for instance, dockerfile, .Dockerfile, Dockerfile.txt, or other, it will not be found.
  • Dockerfile is not in context. If you say docker build contextdir, the Dockerfile must be at contextdir/Dockerfile. If you have it in, say, ./Dockerfile instead, it will not be found.
  • Dockerfile does not exist at all. Does it sound silly? Well, I got the above error message from my GitLab CI after I had written a nice Dockerfile, but I had forgotten to check it in. Silly? Sure. Unlikely? No.
Cranmer answered 30/8, 2019 at 9:47 Comment(3)
Additional tip that solved my problem with the same message: be sure to have your CaSinG correct. For Directory path as well as the Dockerfile. Since linux is pretty picky about that.Efficiency
Filename did the trick for me. I had to change DockerFile to DockerfilePortaltoportal
Likewise, check for simple spelling errors. I landed here because Dockefile is certainly not the same as Dockerfile :facepalm: Since building with docker build -f <tab-completed filename> . worked, I looked closer and realized I had mistyped it.Amen
F
50

If you are working on Windows 8, you would be using Docker toolbox.

From the mydockerbuild directory, run the below command as your Dockerfile is a textfile:

docker build -t docker-whale -f ./Dockerfile.txt .
Felid answered 2/3, 2017 at 5:53 Comment(4)
for future reference if you need to do this it is because your Dockerfile has an extension whereas by default Docker expects it not too. Setting the file manually with the extension adds headaches you do not need. You should set Windows explorer to show extensions and then remove the extension.Serna
if you're following along on the docker documentation "getting started" tutorial you would use this: docker build -t friendlyhello -f ./Dockerfile.txt .Cue
Its really bad semantics that you have to specify the file name and the dummy path also. and/or always name your file as Dockerfile.. :-(Tapia
This saved my day. By the way, I'm using a Mac machine. But the catch here is that the Dockerfile was created a plain text file. Thanks buddy for the help.Louvre
H
29

The name of the file should be Dockerfile and not .Dockerfile. The file should not have any extension.

Hartzog answered 27/3, 2019 at 15:56 Comment(0)
F
28
  1. Make sure you moved to the directory where Dockerfile is located.
  2. Make sure your Dockerfile is extension-less. That is, not Dockerfile.txt, Dockerfile.rtf, or any other.
  3. Make sure you named Dockerfile, and not DockerFile, dockerfile or any other.
Fonsie answered 9/3, 2021 at 7:40 Comment(1)
big help on the Dockerfile instead of DockerFileAudwin
L
20

I had named my file dockerfile instead of Dockerfile (capitalized), and once I changed that, it started processing my "Dockerfile".

Latreshia answered 9/1, 2017 at 22:57 Comment(1)
I cloned a json file instead of creating a new file. Once i renamed it to Dockerfile and updated it contents, it didn't show .json extension and later realised thats the culprit! Thanks for the note!Emanate
R
16

Just remove the extension .txt from Dockerfile and run the command

docker build -t image-name

It will work for sure.

Riccio answered 13/2, 2017 at 15:10 Comment(0)
E
12

I have got this error (in a MacBook) though I used the correct command to create the image,

docker build -t testimg .

Later I found that the path is the problem. Just navigate to the correct path that contains the Docker file. Just double check your current working directory. Nothing to panic about!

Eurythermal answered 8/11, 2017 at 19:15 Comment(0)
W
7

This command worked for me:

docker build -t docker-whale -f Dockerfile.txt .
Walkyrie answered 13/8, 2019 at 15:48 Comment(1)
Dockerfile is not a .txt file. If you have it as a .txt file it will give error again.Kenyon
T
5

That's just because Notepad add ".txt" at the end of Dockerfile.

Traver answered 4/2, 2017 at 17:34 Comment(1)
And Windows hides it?Fewer
E
4

I had created my DockerFile by the Visual Studio 2017 Docker Support tool and had the same error.

After a while, I realised I was not in the correct directory that contains the Dockerfile (~\source\repos\DockerWebApplication\). I cd'ed to the correct file (~/source/repos/DockerWebApplication/DockerWebApplication) which was inside the project and successfully created the Docker image.

Eklund answered 25/11, 2018 at 12:33 Comment(1)
DockerFile is the wrong file name. It should be Dockerfile.Fewer
U
4

In WSL, there seems to be a problem with path conversion. The location of the Dockerfile in Ubuntu (where I'm running Docker and where Dockerfile lives) is "/home/sxw455/App1", but neither of these commands worked:

$ pwd

/home/sxw455/App1

$ ll

total 4
drwxrwxrwx 0 sxw455 sxw455 4096 Dec 11 19:28 ./
drwxr-xr-x 0 sxw455 sxw455 4096 Dec 11 19:25 ../
-rwxrwxrwx 1 sxw455 sxw455  531 Dec 11 19:26 Dockerfile*
-rwxrwxrwx 1 sxw455 sxw455  666 Dec 11 19:28 app.py*
-rwxrwxrwx 1 sxw455 sxw455   12 Dec 11 19:27 requirements.txt*

$ docker build -t friendlyhello .

unable to prepare context: unable to evaluate symlinks in Dockerfile path: GetFileAttributesEx C:\Windows\System32\Dockerfile: The system cannot find the file specified.

$ docker build -t friendlyhello "/home/sxw455/App1"
unable to prepare context: path "/home/sxw455/App1" not found

But in Windows, the actual path is:

C:\Users\sxw455\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\sxw455\App1

And so I had to do this (even though I ran it from Bash):

$ docker build -t friendlyhello

"C:\Users\sxw455\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\sxw455\App1"

Sending build context to Docker daemon   5.12kB
Step 1/7 : FROM python:2.7-slim
 ---> 0dc3d8d47241
Step 2/7 : WORKDIR /app
 ---> Using cache
 ---> f739aa02ce04
Step 3/7 : COPY . /app
 ---> Using cache
 ---> 88686c524ae9
Step 4/7 : RUN pip install --trusted-host pypi.python.org -r requirements.txt
 ---> Using cache
 ---> b95f02b14f78
Step 5/7 : EXPOSE 80
 ---> Using cache
 ---> 0924dbc3f695
Step 6/7 : ENV NAME World
 ---> Using cache
 ---> 85c145785b87
Step 7/7 : CMD ["python", "app.py"]
 ---> Using cache
 ---> c2e43b7f0d4a
Successfully built c2e43b7f0d4a
Successfully tagged friendlyhello:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

I had similar problems with environment variables during the initial installation, and followed some advice that said to install the Windows DockerCE and hack the environment variables rather than installing the Ubuntu DockerCE, because (I hope I remembered this correctly) that WSL does not fully implement systemctl. Once the Windows Docker CE installation is done and environment variables are set, docker then works fine under WSL/Ubuntu.

Upsilon answered 12/12, 2018 at 1:8 Comment(1)
This worked for me! I only installed Docker Toolbox and didn't install it in WSL; instead, I'm using the windows executables directly, since WSL can do that now.Prototherian
K
3

In Windows 10, period is the first parameter:

docker build . -t docker-whale

Koto answered 4/11, 2016 at 13:3 Comment(1)
not anymore (if ever) docker build -t docker-whale . is a valid commandIncur
S
3

Two ways to build a dockerfile:

You can decide not to specify the file name of which to build from and just build it specifying a path (doing it this way the file name must be Dockerfile with no extension appended, eg: docker build -t docker-whale:tag path/to/Dockerfile

or

You can specify a file with -f and it doesn't matter what extension (within reason .txt, .dockerfile, .Dockerfile etc..) you decide to use, eg docker build -t docker-whale:tag /path/to/file -f docker-whale.dockerfile.

Sandarac answered 10/11, 2019 at 14:46 Comment(0)
T
3

The error means that docker build is either using a PATH | URL that are incorrectly input or that the Dockerfile cannot be found in the current directory. Also, make sure that when running the command from an integrated terminal (e.g. bash inside your IDE or text editor) you have the admin permissions to do so. Best if you can check the PATH from your terminal with pwd (in bash shell or dir if using a simple cli on windows) and copy the exact path where you want the image to be build.

docker build C:\windows\your_amazing_directory

docker build --help will also show you available options to use in case of malformed or illegal commands.

Triboluminescence answered 14/7, 2020 at 8:38 Comment(0)
A
2

I had originally created my Dockerfile in PowerShell and though I didn't see an extension on the file it showed as a PS File Type...once I created the file from Notepad++ being sure to select the "All types (.)" File Type with no extension on the File Name (Dockerfile). That allowed my image build command to complete successfully...Just make sure your Dockerfile has a Type of "File"...

Alves answered 23/6, 2017 at 13:32 Comment(0)
H
2

The problem is that the file name should be Dockerfile and not DockerFile or dockerfile. It should be D capital followed by ockerfile in lowercase. Please note.

Hatteras answered 23/5, 2018 at 10:21 Comment(0)
G
2

I my case (run from Windows 10):

  1. Rename the file myDockerFile.Dockerfile to Dockerfile (without file extension).

Then run this command from outside the folder:

docker build .\Docker-LocalNifi\

This is working for me and for my colleagues at work.

Gassing answered 2/4, 2019 at 8:57 Comment(0)
F
2

Be sure your Dockerfile is in the ROOT of the application directory, I had mine in src which resulted in this error because Docker was not finding the path to Dockerfile

Fushih answered 13/11, 2019 at 10:30 Comment(2)
Is this a bogus answer? The name of the file is Dockerfile, not DOCKERfile.Fewer
changed the filenameFushih
S
2

In case if we have multiple Docker files in our environment just Dockerfile won’t suffice for our requirement.

docker build -t ihub -f Dockerfile.ihub .

So use the file (-f argument) command to specify your docker file (Dockerfile.ihub).

Sussex answered 8/5, 2020 at 7:26 Comment(2)
It's also necessary to have the . (dot) at the end of the line, as the above shows.Paperback
Documentation for docker build is here: docs.docker.com/engine/reference/commandline/buildPaperback
S
2

Installing docker.io instead of docker helped me

i.e.

apt install docker.io
Speedwell answered 3/12, 2022 at 19:56 Comment(2)
What is "docker.io"?Fewer
What is docker.io in relation to docker-ce and docker-ee (now called "Mirantis Kubernetes Engine")?Fewer
O
2

This seems to be an issue when you install docker with snap.

  1. First Remove the docker if you used snap -

    sudo snap remove docker

  2. Install docker using apt

    sudo apt install docker.io

Oppenheimer answered 26/9, 2023 at 14:53 Comment(0)
T
1

To build Dockerfile, save the automated content in Dockerfile. Not Dockerfile because while opening a file command:

notepad Dockerfile

(A text file is written so the file cannot build.)

To build the file, run:

notepad Dockerfile

and now run:

docker build -t docker-whale .

Make sure you are in the current directory of Dockerfile.

Tong answered 16/2, 2017 at 6:5 Comment(1)
What do you mean by the first part? That file Dockerfile can not be changed while it is open in Notepad?Fewer
D
1

Most importantly, make sure your file name is Dockerfile. If you use another name it won't work (at least it did not for me).

Also if you are in the same directory where the Dockerfile is use a ., i.e.,

docker build -t Myubuntu1:v1 .

Or use the absolute path, i.e.,

docker build -t Myubuntu1:v1 /Users/<username>/Desktop/Docker

Diapause answered 28/1, 2019 at 12:27 Comment(0)
A
1

Make sure file name "Dockerfile" is not saved with any extension. Just create a file without any extension.

And make sure Dockerfile is in the same directory from where you are trying to build the Docker image.

Acquah answered 16/4, 2019 at 5:0 Comment(0)
M
1

Make sure you run the command

docker build . -t docker-whale 

from the directory that has the dockerfile

Maighdlin answered 8/9, 2020 at 15:26 Comment(1)
This seems to be repeat of previous answers.Fewer
C
1

This issue can also happen when having trailing spaces after the backslash \ character, to reproduce the issue:

  1. Create an empty Dockerfile
    echo "FROM alpine" > Dockerfile
    
  2. Run the build command - there's a trailing space after \, which causes the issue
    docker build -t test \ 
    -t another-tag .
    
    Output of the above command:
    ERROR: unable to prepare context: path " " not found
    
  3. Fixed by removing the trailing space after \
    docker build -t test \
    -t another-tag .
    
    Output - it works 😊
Clareclarence answered 27/7, 2023 at 9:18 Comment(0)
A
1

My issues was a little different when getting this error.

I was trying to deploy to Artifact Registry on Google Cloud and I didn't realize it was using my .gitignore file, where I had listed my Dockerfile to be excluded from upload to Github. It was skipping the Dockerfile and as soon as I deleted it, it worked again.

Ashlar answered 4/3 at 20:35 Comment(0)
M
0

I got this on Windows when the path I was working in was under a junction point directory. So my fix was to not work under that path.

Middy answered 16/5, 2017 at 21:25 Comment(0)
A
0

On Mac it works for the below command (I hope your .Dockerfile is in your root directory).

docker build -t docker-whale -f .Dockerfile .
Azzieb answered 14/5, 2018 at 6:17 Comment(0)
C
0

The issue is related to the DockerFile creation procedure.

In order to work, open cmd, cd to the directory of interest and type:

abc>DockerFile

This will create a file called DockerFile inside your folder.

Now type:

notepad DockerFile

This will open the DockerFile file in Notepad and you will have to copy/paste the standard code provided.

Save the file and now, finally, build your image with Docker typing:

docker build -t docker-whale .

This is working for me.

Circumspect answered 31/10, 2018 at 12:32 Comment(2)
What is 'abc'? Wouldn't that result in "command not found" (to standard error)?Fewer
Is this a bogus answer? DockerFile is the wrong file name. It should be Dockerfile.Fewer
B
0

I erroneously created Dockerfile.txt in my working directory leading to the above-mentioned error while build

The fix was to remove the .txt extension from the file.

The file name should be Dockerfile only without any extension.

Bruno answered 14/5, 2020 at 13:57 Comment(0)
L
0

Execute docker build -t getting-started . in your project directory and make sure Dockerfile is present and having no .txt extension. If you are on Windows, check the 'file name extension' in the under the view tab in the File Explorer to show whether .txt is there or not and remove it if the former is true. Good Luck.

Ladida answered 28/5, 2020 at 17:51 Comment(0)
C
0

I also faced the same issues, and it was resolved when I created a file named with DockerFile and mentioned all the commands which wanted to get executed during creation of the image.

Cottonseed answered 6/6, 2020 at 14:28 Comment(1)
But it isn't DockerFile. It is Dockerfile. Is this just repeating some of the incorrect answers?Fewer
L
0

If you have mounted a second drive to an NTFS folder as a 'mounted volume' then you can get this issue.

Move you files to a drive location outside of the mounted volume.

Lemmy answered 13/8, 2020 at 10:47 Comment(2)
Why is that a problem? What is the mechanism?Fewer
@PeterMortensen See more here github.com/docker/for-win/issues/8110#issuecomment-723469794Lemmy
A
0

Please check whether Docker is running on your Windows installation or not. I tried to find the solution and then accidentally checked and found the issue.

Assiniboine answered 23/8, 2020 at 20:28 Comment(0)
R
0

In Linux, folders are case sensitive.

I was getting this error because of the folder name TestAPI, and I was using TestApi.

Raveaux answered 8/2, 2021 at 8:0 Comment(0)
G
0

docker build -t docker-whale -f DockerFile .

Guardi answered 26/7, 2022 at 12:9 Comment(1)
How is this different from the previous answers? What is it supposed to do?Fewer
P
0

The issue is in your GitHub workflow.

- uses: actions/checkout@v3  # <-- This is what you need to add 
- name: Build and Tag the Docker image
  run: docker build -t docker-whale .
Popovich answered 19/5, 2023 at 13:29 Comment(0)
W
0

For those using minikube image build, make sure that your .dockerignore does not include your Dockerfile.

Whittaker answered 26/6, 2023 at 15:4 Comment(0)
C
0

I got this same error on Mac. But i was able to solve it by adding Sudo.

sudo docker build -t docker-whale .

Conjugal answered 17/9, 2023 at 21:18 Comment(0)
H
0

If you are using a file name other DockerFile, none of the following works. Docker expect a file with name DockerFile in current directory.

docker build  myfile
docker build  -t myfile

#you get this error
[+] Building 0.0s (0/0)                                                                                                                                                                      
ERROR: unable to prepare context

As per the documentation here.https://docs.docker.com/engine/reference/commandline/image_build/

In ubuntu the Right command will provide the inputstream that contains content of a dockerfile

docker build - < MyDockerFilePathOrName

hyphon -

For windows you can use powershell

Get-Content MyDockerFilePathOrName | docker build -
Halbeib answered 5/2 at 16:22 Comment(0)
C
-1

To build an image from the command-line in Windows or Linux.

  1. Create a Docker file in your current directory.

    For example,

     FROM ubuntu
     RUN apt-get update
     RUN apt-get -y install apache2
     ADD . /var/www/html
     ENTRYPOINT apachectl -D FOREGROUND
     ENV name Devops_Docker
    
  2. Don't save it with the .txt extension.

  3. Under command-line run the command

     docker build . -t apache2image
    
Corneille answered 28/9, 2019 at 4:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.