The 'operation was cancelled' error occurs when a Docker operation is interrupted before completion. This typically happens due to user cancellation, timeouts, resource constraints, or Docker Desktop connectivity issues.
The "operation was cancelled" error is a gRPC status message indicating that a Docker operation was terminated before it could complete. This error originates from Docker's internal communication layer, which uses gRPC (Google Remote Procedure Call) for client-daemon interactions. When you see this error, it means the Docker client received a cancellation signal for an in-progress operation. This can happen in several scenarios: the user explicitly cancelled the operation (e.g., pressing Ctrl+C), the operation exceeded its timeout deadline, Docker Desktop lost connection to its backend services, or the Docker daemon became unresponsive. Unlike the related "context deadline exceeded" error which specifically indicates a timeout, "operation was cancelled" is more generic and can result from various interruption sources. The error is common during long-running operations like image builds, large image pulls, or when Docker Desktop is starting up or shutting down.
The simplest fix for transient cancellation errors is restarting Docker Desktop:
On Windows/Mac:
1. Right-click the Docker Desktop icon in the system tray/menu bar
2. Select "Restart"
3. Wait for Docker Desktop to fully start (icon stops animating)
On Linux (systemd):
sudo systemctl restart dockerAfter restart, verify Docker is running:
docker infoIf Docker Desktop shows "Docker Desktop stopped" repeatedly, proceed to the next steps.
Large build contexts with many files can cause cancellation during loading. Create or update your .dockerignore file:
# Create .dockerignore in your project root
touch .dockerignoreAdd common directories that should be excluded:
# Dependencies
node_modules/
vendor/
.venv/
venv/
__pycache__/
# Build outputs
dist/
build/
target/
*.egg-info/
# IDE and editor files
.idea/
.vscode/
*.swp
*.swo
# Git
.git/
.gitignore
# Docker files (avoid recursive issues)
Dockerfile*
docker-compose*.yml
# Logs and temp files
*.log
tmp/
temp/This significantly reduces the number of files Docker needs to process during build context creation.
IDEs like VS Code, RStudio, and JetBrains products can lock files, preventing Docker from accessing them during build:
Before running docker build:
1. Close your IDE completely (not just minimize)
2. Or run the docker command from an external terminal (not the IDE's integrated terminal)
For VS Code specifically:
- The file watcher and extensions may lock files during indexing
- Wait for VS Code to finish "restoring packages" or "indexing" before building
- Consider running docker build from Windows Terminal, PowerShell, or a separate command prompt
For RStudio:
- RStudio locks files it's using; close the project before building
This is especially important on Windows where file locking is more strict.
If you're running docker build from a different directory than your Dockerfile location, Docker may include unexpected files:
# Bad: Running from root while Dockerfile is in subdirectory
# This includes ALL files from current directory in build context
cd /
docker build -f /project/Dockerfile .
# Good: Run from the project directory
cd /project
docker build .
# Or specify the context explicitly
docker build -f /project/Dockerfile /projectAn inflated build context causes longer loading times and potential cancellation:
# Check your build context size
du -sh . --exclude=.gitIf the context is larger than expected, review what's being included.
If Docker Desktop is in an inconsistent state, resetting can resolve persistent issues:
On Windows:
1. Open Docker Desktop
2. Click the gear icon (Settings)
3. Navigate to "Troubleshoot"
4. Click "Reset to factory defaults"
5. Confirm and wait for Docker to restart
On Mac:
1. Click Docker Desktop in menu bar
2. Select Preferences > Troubleshoot
3. Click "Reset to factory defaults"
Alternative: Clean reset via command line (Windows):
# Stop Docker Desktop
Stop-Process -Name "Docker Desktop" -Force
# Remove Docker Desktop data
Remove-Item -Recurse -Force "$env:APPDATA\Docker"
Remove-Item -Recurse -Force "$env:LOCALAPPDATA\Docker"
# Restart Docker Desktop
Start-Process "C:\Program Files\Docker\Docker\Docker Desktop.exe"Warning: This removes all containers, images, and volumes. Back up important data first.
On Windows, WSL2 integration issues can cause operation cancellations:
Update WSL2 kernel:
wsl --updateRestart WSL:
wsl --shutdownVerify WSL2 is the default version:
wsl --set-default-version 2Check Docker Desktop settings:
1. Open Docker Desktop Settings
2. Go to "General"
3. Ensure "Use the WSL 2 based engine" is checked
Edit settings.json if Docker Desktop won't start:
# Edit the settings file
notepad $env:APPDATA\Docker\settings.jsonEnsure "wslEngineEnabled": true is set, then restart Docker Desktop.
Docker Desktop requires hardware virtualization and specific Windows features:
Check virtualization status:
# In PowerShell
systeminfo | findstr /i "virtualization"If virtualization is disabled, enable it in BIOS:
1. Restart your computer and enter BIOS (usually F2, F10, Del, or Esc during boot)
2. Find "Virtualization Technology", "VT-x", or "AMD-V"
3. Enable it and save changes
Enable required Windows features:
# Enable Hyper-V (Windows Pro/Enterprise)
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
# Enable WSL
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
# Enable Virtual Machine Platform
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatformRestart your computer after enabling features.
If problems started after a Docker Desktop update, try an older version:
Download previous versions:
- Visit: https://docs.docker.com/desktop/release-notes/
- Or: https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe (Windows)
Common stable versions to try:
- Docker Desktop 4.22.x (known stable for many users)
- Docker Desktop 4.19.x
Steps:
1. Uninstall current Docker Desktop
2. Download the older installer
3. Install the previous version
4. In Settings, disable automatic updates temporarily
# Uninstall via command line (Windows)
& "C:\Program Files\Docker\Docker\Docker Desktop Installer.exe" uninstallAfter downgrading, verify the issue is resolved before re-enabling updates.
Resource exhaustion can cause operations to be cancelled:
# Check Docker disk usage
docker system df
# Remove unused data (safe cleanup)
docker system prune
# More aggressive cleanup (removes all unused images)
docker system prune -a
# Clean BuildKit cache specifically
docker builder prune --allCheck available disk space:
# Linux/Mac
df -h
# Windows PowerShell
Get-PSDrive C | Select-Object Used,FreeEnsure you have at least 10-20GB free for Docker operations. For Docker Desktop, you can also adjust the disk image size limit in Settings > Resources.
BuildKit Context Cancellation: When BuildKit shows "CANCELED [frontend internal] load build context", this is often normal behavior. BuildKit runs steps in parallel and may cancel a step when it determines (through cache checking) that the step isn't needed. This is not an error unless the entire build fails.
VS Code Docker Extension: The "Operation cancelled" error in the VS Code Docker extension (when removing containers or images) is often a timeout issue with the extension's gRPC client. Try the operation from the command line instead, or restart VS Code.
macOS Security & Privacy: On macOS, Docker Desktop requires permission to access your file system. If builds are failing, check System Preferences > Security & Privacy > Privacy > Files and Folders to ensure Docker has access.
Antivirus Interference: Windows Defender and other antivirus software can interfere with Docker's file operations. Try adding exclusions for:
- Docker Desktop installation directory
- WSL2 file locations (\\wsl$\)
- Your project directories
Docker Context Issues: If you have multiple Docker contexts configured, ensure you're using the correct one:
docker context ls
docker context use defaultMemory Constraints: On Docker Desktop, if you're building large images or running many containers, increase the memory limit in Settings > Resources > Advanced. Insufficient memory can cause operations to be terminated.
image operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker
cannot open '/etc/passwd': Permission denied
How to fix 'cannot open: Permission denied' in Docker
Error response from daemon: failed to create the ipvlan port
How to fix 'failed to create the ipvlan port' in Docker
toomanyrequests: Rate exceeded for anonymous users
How to fix 'Rate exceeded for anonymous users' in Docker Hub