How to fix Error: operation was cancelled in Docker

DockerBEGINNERMEDIUMUpdated Dec 6, 2025· 323 views

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.

Quick fix

Fixes Error: operation was cancelled

sudo systemctl restart docker
  1. Restart Docker Desktop
  2. Add a .dockerignore file to reduce build context
  3. Close IDEs and applications that lock files
  4. Run Docker build from the correct directory
docker — error
sudo systemctl restart docker
Error: operation was cancelled

What this error means

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.

Typical symptoms

  • Docker build fails with 'error: operation was cancelled' during context loading
  • Docker pull interrupted with cancellation error before completing
  • Docker Desktop shows 'Docker Desktop stopped' with operation cancelled messages in logs
  • Docker Compose operations fail partway through with cancellation errors
  • CI/CD pipeline docker commands fail intermittently with this error
  • Container start operations fail after Docker Desktop restart
  • VS Code Docker extension shows operation cancelled when removing containers
  • Build context loading shows 'CANCELED' status in BuildKit output

Common causes

  1. User interrupted the operation with Ctrl+C or similar cancellation signal
  2. Docker Desktop lost connection to its backend (WSL2, Hyper-V, or VM)
  3. IDE or editor locking files during build context loading
  4. Large build context with many files exceeding internal timeouts
  5. Docker daemon restarting or shutting down during an operation
  6. Insufficient system resources (memory, CPU) causing operation failures
  7. Network connectivity issues during registry operations
  8. Antivirus or security software interfering with Docker file operations
  9. WSL2 integration issues on Windows systems
  10. Docker Desktop in inconsistent state requiring reset

How to fix "Error: operation was cancelled"

1Restart Docker Desktop

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

bash
sudo systemctl restart docker

After restart, verify Docker is running:

bash
docker info

If Docker Desktop shows "Docker Desktop stopped" repeatedly, proceed to the next steps.

2Add a .dockerignore file to reduce build context

Large build contexts with many files can cause cancellation during loading. Create or update your .dockerignore file:

bash
# Create .dockerignore in your project root
touch .dockerignore

Add common directories that should be excluded:

bash
# 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.

3Close IDEs and applications that lock files

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.

4Run Docker build from the correct directory

If you're running docker build from a different directory than your Dockerfile location, Docker may include unexpected files:

bash
# 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 /project

An inflated build context causes longer loading times and potential cancellation:

bash
# Check your build context size
du -sh . --exclude=.git

If the context is larger than expected, review what's being included.

5Reset Docker Desktop to factory defaults

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

powershell
# 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.

6Fix WSL2 issues on Windows

On Windows, WSL2 integration issues can cause operation cancellations:

Update WSL2 kernel:

powershell
wsl --update

Restart WSL:

powershell
wsl --shutdown

Verify WSL2 is the default version:

powershell
wsl --set-default-version 2

Check 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:

powershell
# Edit the settings file
notepad $env:APPDATA\Docker\settings.json

Ensure "wslEngineEnabled": true is set, then restart Docker Desktop.

7Enable virtualization and required Windows features

Docker Desktop requires hardware virtualization and specific Windows features:

Check virtualization status:

powershell
# 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:

powershell
# 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 VirtualMachinePlatform

Restart your computer after enabling features.

8Downgrade Docker Desktop if issues persist

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

powershell
# Uninstall via command line (Windows)
& "C:\Program Files\Docker\Docker\Docker Desktop Installer.exe" uninstall

After downgrading, verify the issue is resolved before re-enabling updates.

9Check and clean Docker resources

Resource exhaustion can cause operations to be cancelled:

bash
# 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 --all

Check available disk space:

bash
# Linux/Mac
df -h

# Windows PowerShell
Get-PSDrive C | Select-Object Used,Free

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

Advanced notes

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:

bash
docker context ls
docker context use default

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

Frequently asked questions

What does "Error: operation was cancelled" mean?
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.
How do I fix "Error: operation was cancelled"?
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.
What causes "Error: operation was cancelled"?
User interrupted the operation with Ctrl+C or similar cancellation signal Docker Desktop lost connection to its backend (WSL2, Hyper-V, or VM) IDE or editor locking files during build context loading
Is the "Error: operation was cancelled" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading