The 'context does not exist' error occurs when Docker CLI attempts to use a context that hasn't been created or has been removed. This typically happens after switching machines, resetting Docker Desktop, or referencing a non-existent context name.
The "context does not exist" error indicates that Docker cannot find the specified context configuration. Docker contexts are a way to manage multiple Docker endpoints (local daemon, remote servers, cloud integrations) from a single CLI installation. Each context stores connection details like the Docker host endpoint, TLS certificates, and orchestrator settings. When you reference a context that doesn't exist in your Docker configuration directory (~/.docker/contexts/), Docker raises this error. This commonly occurs when you've cloned a Docker configuration from another machine, when Docker Desktop has been reset, when the context was manually deleted, or when there's a typo in the context name. The error may also appear in CI/CD pipelines where context names differ between environments.
First, check which contexts are currently available on your system:
# List all Docker contexts
docker context lsThis shows all configured contexts with an asterisk (*) marking the currently active one. If the context you're trying to use isn't listed, it needs to be created.
If you see an error even running this command, the current context itself may be invalid.
If you're stuck with an invalid context, switch back to the default:
# Switch to default context
docker context use defaultIf this fails because "default" doesn't exist (common after Docker Desktop reset), you may need to fix the config file manually (see next step).
If Docker is configured to use a context that no longer exists, edit the config file:
# View current config
cat ~/.docker/config.jsonLook for a line like:
"currentContext": "mycontext"Remove this line entirely or change it to "default":
# On Linux/Mac - edit the file
nano ~/.docker/config.json
# Or use sed to remove the line
sed -i '/"currentContext"/d' ~/.docker/config.jsonOn Windows, the config file is typically at %USERPROFILE%\.docker\config.json.
Environment variables override Docker context settings. Check if any are set:
# Check for Docker-related environment variables
env | grep DOCKER
# Common variables that affect context
echo $DOCKER_CONTEXT
echo $DOCKER_HOSTIf DOCKER_CONTEXT is set to a non-existent context, unset it:
# Temporarily unset
unset DOCKER_CONTEXT
unset DOCKER_HOST
# Or permanently remove from your shell profile
# Edit ~/.bashrc, ~/.zshrc, or ~/.profile and remove the linesIf you need to create a new context (for a remote Docker host, for example):
# Create context for a remote Docker host
docker context create mycontext --docker "host=ssh://user@remote-host"
# Create context with TCP endpoint
docker context create mycontext --docker "host=tcp://192.168.1.100:2376"
# Create context for local Docker socket
docker context create mycontext --docker "host=unix:///var/run/docker.sock"Then switch to use it:
docker context use mycontextFor Docker Desktop users (Windows/Mac), if the desktop-linux or default context is missing:
# Check Docker Desktop status
docker versionIf Docker Desktop is running but contexts are broken:
1. Open Docker Desktop settings
2. Go to "Troubleshoot" (bug icon)
3. Click "Reset to factory defaults" or "Clean / Purge data"
Alternatively, manually reset contexts:
# Remove all context directories (Linux/Mac)
rm -rf ~/.docker/contexts
# Restart Docker Desktop
# The default context will be recreatedWarning: This removes all custom contexts. Back up any important context configurations first.
If docker-compose fails to find a context that works with docker:
# Check docker-compose version
docker-compose version
# Use the newer docker compose (plugin) instead
docker compose versionThe standalone docker-compose may have compatibility issues with certain Docker CLI versions. Try using the plugin version:
# Instead of: docker-compose --context mycontext up
docker compose --context mycontext up
# Or set the context first
docker context use mycontext
docker compose upContext Storage Location: Docker contexts are stored in ~/.docker/contexts/. Each context has a directory named with a hash of the context name, containing a meta.json file with the context configuration. If the directory name doesn't match the expected hash, the context may be listed but fail to be used.
Minikube Integration: When using Minikube with Docker driver, Minikube creates its own Docker context. If you see "Unable to resolve the current Docker CLI context 'default'" after a Minikube upgrade, try:
minikube docker-env --unset
eval $(minikube docker-env)VS Code / Visual Studio Integration: IDEs that use Docker may cache context information. After fixing context issues, restart the IDE or reload the Docker extension.
Windows-specific Issues: On Windows with WSL2, you may have separate Docker contexts for Windows and WSL2. Check both:
- Windows: %USERPROFILE%\.docker\config.json
- WSL2: ~/.docker/config.json
Rancher Desktop: If using Rancher Desktop instead of Docker Desktop, the context may be named differently. Check docker context ls and use the appropriate context name.
CI/CD Pipelines: When running Docker in CI/CD, avoid relying on context configuration. Instead, explicitly set DOCKER_HOST or use the --host flag:
docker --host tcp://docker-host:2376 psdockerfile parse error line 5: unknown instruction: RRUN
How to fix 'unknown instruction' Dockerfile parse error in Docker
Error response from daemon: manifest for nginx:nonexistent not found: manifest unknown: manifest unknown
How to fix 'manifest for image:tag not found' in Docker
Error response from daemon: invalid reference format: repository name must be lowercase
How to fix 'repository name must be lowercase' in Docker
Error response from daemon: No such image
How to fix 'No such image' in Docker
Error response from daemon: Container is not running
How to fix 'Container is not running' when using docker exec