docker-context
Manage Docker connection configurations
TLDR
Create a context using a specific Docker endpoint
Create a context based on the DOCKER_HOST environment variable
Switch to a context
List all contexts
SYNOPSIS
docker context COMMAND
docker context [OPTIONS] COMMAND
Common Commands:
docker context create [OPTIONS] CONTEXT
docker context ls [OPTIONS]
docker context use CONTEXT
docker context inspect [OPTIONS] [CONTEXT...]
docker context rm [OPTIONS] CONTEXT [CONTEXT...]
PARAMETERS
create
Create a new Docker context.
export
Export a context to a tar file.
import
Import a context from a tar file.
inspect
Display detailed information on one or more contexts.
ls
List Docker contexts.
rm
Remove one or more contexts.
use
Set the current Docker context.
update
Update a context.
DESCRIPTION
The docker context command group is part of the Docker CLI, designed to manage connections to different Docker daemons. A "Docker context" encapsulates the configuration needed to connect your Docker CLI to a specific Docker host or cluster. This can be a local Docker Desktop instance, a remote Docker Engine running on a cloud VM, a Docker Swarm cluster, or even integration with Kubernetes, Azure Container Instances (ACI), or Amazon Elastic Container Service (ECS) via Docker Desktop.
It enables users to seamlessly switch between various development, testing, and production environments without manually changing environment variables or complex configurations. Key functionalities include creating new contexts, listing existing ones, switching the active context, inspecting context details, and removing contexts.
CAVEATS
Contexts abstract connection details, but underlying network access (firewall, SSH, VPN) must still be correctly configured.
Switching contexts affects all subsequent Docker commands in the current shell session, which can lead to accidental operations on the wrong environment if not mindful.
Managing many contexts can become complex; naming conventions are important.
DEFAULT CONTEXT
The default context is usually named "default" and points to the local Docker daemon (e.g., Docker Desktop or a local Linux installation).
CONTEXT TYPES
Contexts can be configured for various backends, including:
docker: Standard Docker Engine (local or remote via TCP/SSH).
kubernetes: Connects to a Kubernetes cluster (often integrated via Docker Desktop's Kubernetes feature).
aci: Azure Container Instances (via Docker Desktop).
ecs: Amazon Elastic Container Service (via Docker Desktop).
USING A CONTEXT
To switch to a context named my_remote_server:
`docker context use my_remote_server`
To run a single command with a specific context without changing the default:
`docker --context my_remote_server ps`
HISTORY
Docker contexts were introduced in Docker Engine 19.03 (2019) to provide a more streamlined and integrated way of managing connections to different Docker daemons, especially in hybrid cloud and multi-cluster environments. Prior to contexts, users typically managed connections via the DOCKER_HOST environment variable or Docker Machine. Contexts offer a more robust, persistent, and user-friendly mechanism to switch between environments, including direct integration with Kubernetes, ACI, and ECS through Docker Desktop.
SEE ALSO
docker(1), docker ps(1), docker-machine(1)