39

i'm trying to build a simple r-base official docker image but it's giving me a strange "context cancelled" error on windows 10.

i've tried pulling the image (which was successful) and then building it but i'm getting the same error. i've also tried reinstalling docker or building any other image (R or not) from Docker Hub but i'm having no luck with it as well. the strange thing is when i reinstalled docker, it ran the getting-started tutorial on shell without problems.

what may be happening?

here's my dockerfile

FROM r-base:4.0.2 COPY . /usr/local/src/myscripts WORKDIR /usr/local/src/myscripts CMD ["Rscript", "main.R"] 

and the shell output

C:\Users\jean\path>docker build -t my-image . [+] Building 1.7s (5/7) => [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 31B 0.0s => [internal] load .dockerignore 0.1s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/r-base:4.0.2 1.4s => CANCELED [internal] load build context 0.1s => => transferring context: 7.08kB 0.0s => CANCELED [1/3] FROM docker.io/library/r-base:4.0.2@sha256:837898ed6a0dc6f9cb0f3d1fa0e801f01673797cdfd3e21c8cd 0.1s => => resolve docker.io/library/r-base:4.0.2@sha256:837898ed6a0dc6f9cb0f3d1fa0e801f01673797cdfd3e21c8cd2ad60f2db 0.0s => => sha256:837898ed6a0dc6f9cb0f3d1fa0e801f01673797cdfd3e21c8cd2ad60f2dbe2da 765B / 765B 0.0s => => sha256:1c4e181b5dbeef804a4bf1f2c6b888b0d2da333b1a5d99f0e1a3ced46b1cdaef 1.58kB / 1.58kB 0.0s => => sha256:673e45d6ffe13b98601b5e19ec2bfbd4ec1b1c135ed9d9e911f6c83c7b9cef1e 5.35kB / 5.35kB 0.0s error from sender: context canceled 
5
  • 2
    I googled the error (without "R" as context), and one github comment in particular seemed appropriate: "This should be an issue with Docker for Windows, as others have also reported (docker-library/docker#71 and docker/for-win#1240). Trying again or updating your Docker installation should fix it.". Common themes: restart/retry, uncheck experimental, upgrade Docker for Windows. Commented Dec 11, 2020 at 3:28
  • thanks, unfortunately already tried reinstalling docker and it didn't work. "experimental features" already disabled, enabling it didn't work either. Commented Dec 11, 2020 at 3:55
  • 1
    unfortunately the problem persisted with the current docker version (3.0.0) so i've downgraded to 2.5.0.0 and it's all working fine now - don't know why, but it's working! Commented Dec 12, 2020 at 18:20
  • I confirm, it did not work with 3.0.0, but worked with 2.5.0 Commented Dec 17, 2020 at 17:56
  • 1
    Here is what also helped, I moved Dockerfile into subdirectory relative to my main code. Commented Dec 17, 2020 at 18:33

16 Answers 16

57

I ran across the same problem, and discovered the issue was with R/RStudio. I was running the docker build through the terminal pane and it kept giving me the "error from sender: context canceled" comment. I believe that R/RStudio locks up the files it is using, which throws a wrench into the docker machinery when it tries to copy the files. Docker built the image with no problem after I closed RStudio and ran the build through a different terminal.

Sign up to request clarification or add additional context in comments.

3 Comments

It can be noted that even if the application is "stopped" r/rstudio still clings to the docker file and locks it
Same issue here with VS Code. My IDE was busy (restoring packages, indexing and compiling) while I ran my docker build command. Executing it in a separate PowerShell window solved the problem while my IDE was still busy
I know the JetBrains IDEs run on VS Code now, so this sort of redundant to the last comment, but I ran into this while using PHPStorm and PyCharm during a docker build. With them closed this issue disappeared.
22

I had the same problem when I was building the image with Docker. The problem is shown in the following image.

Docker build error

After that I closed RStudio, it worked!

3 Comments

In my case it worked when I closed IntelliJ Idea, however it worked sometimes when idea was open. Don't know why
Confirmed. Strange
@AmitKumar, IDE sometimes locks files, or subprocesses do. In my case with Rider, it was _Resharper.Caches directory. I added every directory no required in the output into .dockerignore file
14

if you want to run docker build from Rstudio, please add a .dockerignore file containing :

.RData .Rhistory .git .gitignore manifest.json rsconnect/ .Rproj.user 

Comments

9

It worked for me after adding .git in .dockerignore file

enter image description here

Comments

2

If you are building a Laravel project with Docker using a bind mount, ensure that you delete the volume folder on your local machine. This is necessary because when attempting to run 'docker-compose up' with a different Dockerfile image, conflicts may arise. in my case i have to delete the folder inside my laravel storage folder.

enter image description here

1 Comment

I had the exact same issue with Laravel and MySQL.
1

I had the same issue when running a Docker build from the RStudio Terminal. For me adding a Windows Firewall rule to allow the app "RStudio Session" fixed it. You can change it by Control Panel

Control Panel\System and Security\Windows Defender Firewall\Allowed apps

Comments

1

Try with sudo in case you are on mac.

Comments

1

In my case it was because a database folder in my project. It seems that all the other guys had a problem with files in a folder maybe.

I added the data folder to .dockerignore file and now build is OK.

If you have not file you can create it.

Comments

1

In my case the problem has been solved by adding generated docker volume directory to .dockerignore.

I hadn't noticed it first, adding .git, .idea and others to no avail. Be especially attentive to volume directories in your project folder.

Comments

0

Got same error when tried to run docker-compose in Visual Studio with Release build. Change to Debug solved the problem.

Comments

0

for windows users, disable 'metered connection' for you network.

Comments

0

I had this issue with docker.

For me it was a problem with my Hard Disk Drive.

My project was in one of my drives and I repeatedly got this error.

So I've moved my project to another drive and the problem gone.

I had some bad sectors.

Maybe this happens to you.

Comments

0

Mine was a similar error, but supposedly with permission denied to some random file. It turned out to be an issue with my SSD. I ran windows tool for error checking on the drive, let it fix errors it found and it started working fine again.

Comments

0

well in my case, the cause was silly. when i run to build application with DOCKER, the application was on running status. so when i shut it down, the error was solved ! hope this would help for guys

Comments

0

My application was still running in intellij when I ran the build. I stopped it in intellij then re-ran docker build. This worked for me hopefully it helps someone else.

Comments

0

I recently faced a challenging issue with Docker builds on my Windows machine and wanted to share my experience for the benefit of others who might encounter something similar.

Issue: While trying to build a Docker image, I kept getting an error: error from sender: context canceled. This was coupled with an unexpectedly large build context size (transferring context: 12.88GB). This was unusual, considering the nature of my project.

Initial Setup: My project was on one drive (let's say Drive F), and I was running the Docker build command from another drive (Drive C). My command specified the path to the Dockerfile using -f, like this:

docker build -f "F:\Path\To\Project\Dockerfile" -t myapp . 

Despite this explicit path, Docker was including all files from the current directory on Drive C, leading to an inflated build context and the failure of the build.

Resolution: The breakthrough came when I realized how Docker determines the build context. It turns out that Docker uses the current working directory as the build context, not just the Dockerfile's directory.

By changing my working directory to the actual project path on Drive F:

F:\Path\To\Project 

and running the same Docker build command, the build processed successfully. The context was now correctly sized, and Docker could utilize cached images efficiently. This success persisted even when using the --no-cache option.

Interestingly, stepping out of the project folder, even by a single level, triggered the 'transferring context: xxxx' process with a large context size, leading to a failure similar to the initial one.

Key Takeaways:

• Docker's build context is defined by the current working directory, not solely by the Dockerfile's location.

• It's crucial to set your working directory to your project's root or the directory representing the necessary context for your Docker build.

• Implementing a .dockerignore file is beneficial, especially in setups involving multiple drives or large directories, to exclude unnecessary files.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.