What is Docker context?
Answer
A Docker context stores the connection configuration needed to connect to a Docker daemon — the endpoint, authentication, and TLS certificates. Docker uses contexts to switch between different Docker environments (local, remote server, Docker Desktop, cloud) without reconfiguring environment variables. Default context: default — connects to the local Docker daemon via /var/run/docker.sock. Commands: docker context ls — list all contexts; docker context use production-server — switch active context; docker context create remote-server --docker "host=ssh://user@server.com" — create SSH-based remote context; docker context inspect contextname — inspect context details. When you switch context, all Docker commands (docker ps, docker run, docker build) execute against that environment. Use cases: (1) Manage multiple remote Docker hosts from your local machine; (2) Switch between Docker Desktop (dev) and a remote Docker host (staging); (3) Docker Desktop creates contexts for different engines (Windows/Linux containers); (4) Used by Docker Compose — DOCKER_CONTEXT env var. With buildx, contexts enable building on remote build machines. SSH context creates an SSH tunnel automatically — no need to expose the Docker daemon socket over TCP (which should be protected with TLS or kept local).
Previous
How does Docker handle logging?
Next
What is the Docker socket and why is exposing it dangerous?