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

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.



Solution 1:[1]

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

Solution 2:[2]

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 .

Solution 3:[3]

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:

Solution 4:[4]

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

Solution 5:[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!

Solution 6:[6]

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.

Solution 7:[7]

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

Solution 8:[8]

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 .

Solution 9:[9]

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.

Solution 10:[10]

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).

Solution 11:[11]

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 .

Solution 12:[12]

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.

Solution 13:[13]

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.

Solution 14:[14]

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

Solution 15:[15]

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.

Solution 16:[16]

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

Solution 17:[17]

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.