How to fix Error: context "mycontext" does not exist in Docker

DockerBEGINNERLOWUpdated Dec 6, 2025ยท 196 views

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
  1. List available contexts
  2. Switch to the default context
  3. Remove invalid context from config.json
  4. Check and unset conflicting environment variables
docker โ€” error
# List all Docker contexts
docker context ls
Error: 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

  1. Context was deleted or never created on this machine
  2. Docker Desktop was reset or reinstalled, clearing context metadata
  3. DOCKER_CONTEXT environment variable references a non-existent context
  4. config.json contains 'currentContext' pointing to a removed context
  5. Context metadata file (meta.json) was corrupted or deleted
  6. Cloned Docker configuration from another machine with different contexts
  7. Typo in context name when using docker context use or --context flag
  8. docker-compose and docker CLI have version incompatibilities
  9. Context directory naming doesn't match the expected hash format

How to fix "Error: context "mycontext" does not exist"

1List available contexts

First, check which contexts are currently available on your system:

bash
# List all Docker contexts
docker context ls

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

2Switch to the default context

If you're stuck with an invalid context, switch back to the default:

bash
# Switch to default context
docker context use default

If this fails because "default" doesn't exist (common after Docker Desktop reset), you may need to fix the config file manually (see next step).

3Remove invalid context from config.json

If Docker is configured to use a context that no longer exists, edit the config file:

bash
# View current config
cat ~/.docker/config.json

Look for a line like:

json
"currentContext": "mycontext"

Remove this line entirely or change it to "default":

bash
# On Linux/Mac - edit the file
nano ~/.docker/config.json

# Or use sed to remove the line
sed -i '/"currentContext"/d' ~/.docker/config.json

On Windows, the config file is typically at %USERPROFILE%\.docker\config.json.

4Check and unset conflicting environment variables

Environment variables override Docker context settings. Check if any are set:

bash
# Check for Docker-related environment variables
env | grep DOCKER

# Common variables that affect context
echo $DOCKER_CONTEXT
echo $DOCKER_HOST

If DOCKER_CONTEXT is set to a non-existent context, unset it:

bash
# Temporarily unset
unset DOCKER_CONTEXT
unset DOCKER_HOST

# Or permanently remove from your shell profile
# Edit ~/.bashrc, ~/.zshrc, or ~/.profile and remove the lines
5Create a new context

If you need to create a new context (for a remote Docker host, for example):

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

bash
docker context use mycontext
6Reinstall or reset Docker Desktop context

For Docker Desktop users (Windows/Mac), if the desktop-linux or default context is missing:

bash
# Check Docker Desktop status
docker version

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

bash
# Remove all context directories (Linux/Mac)
rm -rf ~/.docker/contexts

# Restart Docker Desktop
# The default context will be recreated

Warning: This removes all custom contexts. Back up any important context configurations first.

7Fix docker-compose context issues

If docker-compose fails to find a context that works with docker:

bash
# Check docker-compose version
docker-compose version

# Use the newer docker compose (plugin) instead
docker compose version

The standalone docker-compose may have compatibility issues with certain Docker CLI versions. Try using the plugin version:

bash
# Instead of: docker-compose --context mycontext up
docker compose --context mycontext up

# Or set the context first
docker context use mycontext
docker compose up

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

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

bash
docker --host tcp://docker-host:2376 ps

Frequently 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