docker build Error checking context: 'can't stat '\\?\C:\Users\username\AppData\Local\Application Data''
Asked Answered
L

19

82

docker build failed on windows 10,

After docker installed successfully, While building docker image using below command.

docker build -t drtuts:latest . Facing below issue. enter image description here

Kindly let me know if any one resolved same issue.

Ladylike answered 22/12, 2016 at 15:1 Comment(2)
Can you add your Dockerfile.Stymie
Were you able to solve the problem . I am facing the same issueDekeles
I
113

The problem is that the current user is not the owner of the directory.
I got the same problem in Ubuntu, this line solves the issue:

Ubuntu

sudo chown -R $USER <path-to-folder>

Source: Change folder permissions and ownership

Windows

This link shows how to do the same in Windows:
Take Ownership of a File / Folder through Command Prompt in Windows 10

Interval answered 26/5, 2020 at 4:53 Comment(1)
this is a "quick fix", but Quinten's answer below goes into more detail and solves the actual problem.Vlf
A
53

Explanation of the problem

When you run the docker build command, the Docker client gathers all files that need to be sent to the Docker daemon, so it can build the image. This 'package' of files is called the context.

What files and directories are added to the context?
The context contains all files and subdirectories in the directory that you pass to the docker build command. For example, when you call docker build img:tag dir_to_build, the context will be everything inside dir_to_build.

If the Docker client does not have sufficient permissions to read some of the files in the context, you get the error checking context: 'can't stat ' <FILENAME> error.

There are two solutions to this problem:

  1. Move your Dockerfile, together with the files that are needed to build your image, to a separate directory separate_dir that contains no other files/subdirectories. When you now call docker build img:tag separate_dir, the context will only contain the files that are actually required for building the image. (If the error still persists that means you need to change the permissions on your files so that the Docker client can access them).
  2. Exclude files from the context using a .dockerignore file. Most of the time, this is probably what you want to be doing.

From the official Docker documentation:

Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context. If this file exists, the CLI modifies the context to exclude files and directories that match patterns in it.

To answer the question

I would create a .dockerignore file in the same directory as the Dockerfile: ~/.dockerignore with the following contents:

# By default, ignore everything
*
# Add exception for the directories you actually want to include in the context
!project-source-code
!project-config-dir
# source files
!*.py
!*.sh

Further reading:

Azov answered 12/1, 2021 at 16:56 Comment(0)
U
48

Just create a new directory and enter it:

$ mkdir dockerfiles
$ cd dockerfiles

Create your file in that directory:

$ touch Dockerfile

Edit it and add the commands with vi:

$ vi Dockerfile

Fnally run it:

$ docker build -t tag .
Unsling answered 31/12, 2016 at 15:26 Comment(4)
The problem is for docker running on windows container not linuxDekeles
Question is why? Why works in /c/Users/myuser/dockerfiles but not /c/Users/myuserPhotolithography
Added dot per #28997407.Holcman
worked on mac ! Thought it was permissions issue. thanksJanellejanene
S
7

Docker grants read and write rights to only to the owner of the file, and sometimes the error will be thrown if the user trying to build is different from the owner.

You could create a docker group and add the users there. in debian would be as follows

sudo groupadd docker

sudo usermod -aG docker $USER

Sophi answered 15/8, 2018 at 15:51 Comment(0)
B
5

I was also getting the same error message on Windows 10 Home version.

I resolved it by the following steps:

  1. Create a directory called 'dockerfiles' under C:\Users\(username)
  2. Keep the {dockerfile without any extension} under the newly created directory as mentioned in step (1).

Now run the command {from C:\Users\(username) directory}: docker build -t ./dockerfiles

It worked like a breeze!

Bernadinebernadotte answered 25/6, 2017 at 6:29 Comment(0)
M
3

I was having the same issue but working with Linux

$ docker build -t foramontano/openldap-schema:0.1.0 --rm .
$ error checking context: 'can't stat '/home/isidoronm/foramontano/openldap_docker/.docker/config/cn=config''.

I was able to solve the problem with the issue... by including the directory referred in the log (/home/isidoronm/foramontano/openldap_docker/.docker) inside the .dockerignore file located in the directory i have the Dockerfile file.(/home/isidoronm/foramontano/openldap_docker )

isidoronm@vps811154:~/foramontano/openldap_docker$ ls -al
total 48
drwxrwxr-x 5 isidoronm isidoronm 4096 Jun 16 18:04 .
drwxrwxr-x 9 isidoronm isidoronm 4096 Jun 15 17:01 ..
drwxrwxr-x 4 isidoronm isidoronm 4096 Jun 16 17:08 .docker
-rw-rw-r-- 1 isidoronm isidoronm   43 Jun 13 17:25 .dockerignore
-rw-rw-r-- 1 isidoronm isidoronm  214 Jun  9 22:04 .env
drwxrwxr-x 8 isidoronm isidoronm 4096 Jun 13 17:37 .git
-rw-rw-r-- 1 isidoronm isidoronm    5 Jun 13 17:25 .gitignore
-rw-rw-r-- 1 isidoronm isidoronm  408 Jun 16 18:03 Dockerfile
-rw-rw-r-- 1 isidoronm isidoronm 1106 Jun 16 17:10 Makefile
-rw-rw-r-- 1 isidoronm isidoronm   18 Jun 13 17:36 README.md
-rw-rw-r-- 1 isidoronm isidoronm 1877 Jun 12 12:11 docker-compose.yaml
drwxrwxr-x 3 isidoronm isidoronm 4096 Jun 13 10:51 service

Maybe it's valid something similar in Windows 10.

Mow answered 16/6, 2020 at 16:25 Comment(0)
G
2

Due to permission issue, this problem caused.

I recommend checking the permission of the respected user, which is accessible in Dockerfile.

Nothing wrong with any path.

Grating answered 31/7, 2018 at 6:57 Comment(0)
C
2

Here are my steps on Windows 10 that worked. Open Command Prompt Window as Administrator:

cd c:\users\ashok\Documents
mkdir dockerfiles
cd dockerfiles
touch dockerfile
notepad dockerfile           # Write/paste here the contents of dockerfile
docker build -t jupyternotebook -f dockerfile .
Candent answered 26/8, 2018 at 16:31 Comment(0)
B
2

I got the same problem in Ubuntu, I just added a sudo before docker build........

Brooklynese answered 8/8, 2020 at 14:5 Comment(1)
Running commands as root when you get a permission denied error is frequently the wrong way forward, even if it does work. It also establishes bad habits that can result in accidentally running malicious code. The solution is learning more about the problem, not trying again with a sudo prefix.Freddie
S
0

I faced a similar situation on Windows 10 and was able to resolve it using the following approach:

  1. Navigate to the directory where your Dockerfile is stored from your CLI (I used PowerShell).
  2. Run the docker build . command

It seems like you are using the bash shell in Windows 10, when I tried using it, docker wasn't even recognized as a command (can check using docker --version).

Ski answered 3/1, 2019 at 20:10 Comment(0)
S
0

On Windows 10

  • Opened command line
  • c:\users\User>
  • mkdir dockerfiles
  • cd dockerfiles
  • notepad Dockerfile.txt

//after notepad opens to type your docker commands and then save your Dockerfile. back to the command line type "python-hello-world" is an example.

  • docker image build -t python-hello-world -f ./Dockerfile.txt .
Stellular answered 31/5, 2019 at 13:56 Comment(0)
S
0

I am writing as it will be helpful to people who play with apparmor

I also got this problem on my Ubuntu machine. It happened because I ran "aa-genprof docker" command to scan "docker" command to create apparmor profile. So the scanned process created a file usr.bin.docker in directory "/etc/apparmor.d", which added some permissions for docker command. So after removing that file and rebooting the machine docker runs again perfectly.

Spavined answered 26/9, 2019 at 20:36 Comment(0)
E
0

If you arrive here with this issue on a Mac, for me I just had to cd back out of the directory containing the Dockerfile, then cd back in and rerun the command and it worked.

Europeanize answered 31/1, 2020 at 21:50 Comment(0)
S
0

I had same issue :- error checking context: 'no permission to read from '\?\C:\Users\userprofile \AppData\Local\AMD\DxCache\36068d231d1a87cd8b4bf677054f884d500b364064779e16..bin''.

it was keep barking this issue , there was no problem with permission tried to run th command and different switch but haven't worked.

created dockerfiles folder and put docker file there and ran command from the folder path

C:\Users\ShaikhNaushad\dockerfiles> docker build -t naushad/debian .

And it worked

Screamer answered 30/5, 2020 at 18:5 Comment(0)
L
0

I faced the same issue while trying to build a docker image from a Dockerfile placed in /Volumes/work. It worked fine when I created a folder dockerfiles within /Volumes/work and placed my Dockerfile in that.

Lillith answered 9/8, 2020 at 18:41 Comment(0)
C
0

Error ? : The folder or directory in that particular location that Docker/current user is trying to modify, has a "different owner"(remember only owners or creators of particular files/documents have the explicit rights to modify those same files).

Or it could also be that the file has already been created and thus this is throwing the Error when a new create statement for a similar file is issued.

Solution ? : Revert ownership of that particular folder and its contents to current user, this can be done in two ways;

  1. sudo rm file (delete file) that particular file and the recreate it using the command "mkdir file".This way you will be the owner/creator of that file. Do this if the data in that file can be rebuilt or is not that crucial
  2. Change the file permissions for that file, follow the following tutorial for linux users :https://www.tomshardware.com/how-to/change-file-directory-permissions-linux
Clump answered 2/5, 2022 at 20:41 Comment(0)
I
0

In my case, I am using a different hard disk only for data, but I use another solid disk for the system, in my case Linux Mint. And the problem was solved when a I change the files to the system disk (solid disk).

PS: I used the command sudo chown -R $USER <path-to-folder> and the problem wasn't solved.

Interfaith answered 28/5, 2022 at 23:57 Comment(0)
W
0

Adding to Quniten's answer, .dockerignore won't work if the problem directory is in you build root, like this:

.
|- Dockerfile
|- sources
|  |- ...
|- .dockerignore
|- .db  # docker does not have access to this dir

.dockerignore:

.db

This still fails to build. Issue on GitHub.

Workaround is to put problem directory into another subdirectory and ignore that, like this:

.
|- Dockerfile
|- sources
|  |- ...
|- .dockerignore
|- .ignored
   |- .db  # docker does not have access to this dir

.dockerignore:

.ignored
Whittington answered 1/9, 2023 at 15:49 Comment(0)
C
0

Fixed this issue by checking that docker daemon is running, also updated and restarted my docker desktop to the latest version.

To start the docker daemon on mac:

Use the open -a docker command in the command-line terminal to launch the docker application on your system.

Celibate answered 26/9, 2023 at 20:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.