How to fix Error: context "mycontext" does not exist in Docker
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.
Quick fix
Fixes Error: context "mycontext" does not exist
# List all Docker contexts
docker context ls- List available contexts
- Switch to the default context
- Remove invalid context from config.json
- Check and unset conflicting environment variables
# List all Docker contextsdocker context lsError: context "mycontext" does not exist
What this error means
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.
Typical symptoms
- Docker commands fail with: Error: context "contextname" does not exist
- Unable to resolve the current Docker CLI context "default": context not found
- docker context use fails with context not found error
- Visual Studio or IDE Docker integration fails to connect
- Docker Compose operations fail when using --context flag
- Kubernetes/Minikube shows 'Unable to resolve the current Docker CLI context'
- Every docker command hangs or fails when configured context is unavailable
- docker context ls shows asterisk on a context that no longer works
Common causes
- Context was deleted or never created on this machine
- Docker Desktop was reset or reinstalled, clearing context metadata
- DOCKER_CONTEXT environment variable references a non-existent context
- config.json contains 'currentContext' pointing to a removed context
- Context metadata file (meta.json) was corrupted or deleted
- Cloned Docker configuration from another machine with different contexts
- Typo in context name when using docker context use or --context flag
- docker-compose and docker CLI have version incompatibilities
- Context directory naming doesn't match the expected hash format
How to fix "Error: context "mycontext" does not exist"
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 upAdvanced notes
Context 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 psFrequently asked questions
- What does "Error: context "mycontext" does not exist" mean?
- 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.
- How do I fix "Error: context "mycontext" does not exist"?
- 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.
- What causes "Error: context "mycontext" does not exist"?
- Context was deleted or never created on this machine Docker Desktop was reset or reinstalled, clearing context metadata DOCKER_CONTEXT environment variable references a non-existent context
- Is the "Error: context "mycontext" does not exist" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Docker Official Documentation
- ๐100 Common Docker Errors & Solutions(Official Docs)
- ๐Docker Docs - Working with contexts(Official Docs)
- ๐Docker Docs - Manage resources with contexts(Official Docs)
- ๐Docker Docs - docker context use(Official Docs)
- ๐ฌStack Overflow - Docker context not changing(Stack Overflow)
- ๐ฌStack Overflow - Unable to resolve Docker CLI context default(Stack Overflow)
- ๐
- ๐
- ๐
- ๐ฌDocker Community Forums - Docker context problem(Stack Overflow)